Repository: TheFriendlyCoder/friendlypins

Issue:
Add accessor to get number of pins on a board
It appears as though there is some optional metadata that can be read from a board API endpoint, one of which contains the total number of pins on that board. We should enhance the Board class to pull down that extra metadata upon instantiation, and provide an accessor that reads the number of pins on the board.

This has the added benefit of not having to read in all the pins contained in the board en-mass to calculate this simple statistic.

Discussion:

Patch:
diff --git a/src/friendlypins/api.py b/src/friendlypins/api.py
index 01b3d4a..ee3b00a 100644
--- a/src/friendlypins/api.py
+++ b/src/friendlypins/api.py
@@ -37,6 +37,7 @@ class API(object):  # pylint: disable=too-few-public-methods
         else:
             temp_url = "{0}/me".format(self._root_url)
         temp_url += "?access_token={0}".format(self._token)
+        temp_url += "&fields=id,username,first_name,last_name,bio,created_at,counts,image"
         response = requests.get(temp_url)
         response.raise_for_status()
 
diff --git a/src/friendlypins/board.py b/src/friendlypins/board.py
index 3a19248..1fea44c 100644
--- a/src/friendlypins/board.py
+++ b/src/friendlypins/board.py
@@ -58,6 +58,14 @@ class Board(object):
         """
         return self._data['url']
 
+    @property
+    def num_pins(self):
+        """Gets the total number of pins linked to this board
+
+        :rtype: :class:`int`
+        """
+        return int(self._data['counts']['pins'])
+
     @property
     def all_pins(self):
         """Gets a list of all pins from this board
diff --git a/src/friendlypins/user.py b/src/friendlypins/user.py
index 78268e5..3121d1d 100644
--- a/src/friendlypins/user.py
+++ b/src/friendlypins/user.py
@@ -79,6 +79,22 @@ class User(object):
         """
         return self._data['url']
 
+    @property
+    def num_pins(self):
+        """Gets the total number of pins owned by this user
+
+        :rtype: :class:`int`
+        """
+        return int(self._data['counts']['pins'])
+
+    @property
+    def num_boards(self):
+        """Gets the total number of boards owned by this user
+
+        :rtype: :class:`int`
+        """
+        return int(self._data['counts']['boards'])
+
     @property
     def boards(self):
         """Gets a list of boards owned by this user
@@ -89,6 +105,7 @@ class User(object):
 
         temp_url = '{0}/me/boards/'.format(self._root_url)
         temp_url += "?access_token={0}".format(self._token)
+        temp_url += "&fields=id,name,url,description,creator,created_at,counts,image"
         response = requests.get(temp_url)
 
         header = Headers(response.headers)


Test patch:
diff --git a/unit_tests/test_board.py b/unit_tests/test_board.py
index fe44dc9..e2eafe1 100644
--- a/unit_tests/test_board.py
+++ b/unit_tests/test_board.py
@@ -6,16 +6,21 @@ def test_board_properties():
     expected_id = 1234
     expected_name = "MyBoard"
     expected_url = "https://www.pinterest.ca/MyName/MyBoard/"
+    expected_pin_count = 42
     sample_data = {
         "id": str(expected_id),
         "name": expected_name,
-        "url": expected_url
+        "url": expected_url,
+        "counts": {
+            "pins": str(expected_pin_count)
+        }
     }
 
     obj = Board(sample_data, 'http://pinterest_url', '1234abcd')
     assert obj.unique_id == expected_id
     assert obj.name == expected_name
     assert obj.url == expected_url
+    assert obj.num_pins == expected_pin_count
 
 def test_get_all_pins():
     data = {
diff --git a/unit_tests/test_user.py b/unit_tests/test_user.py
index 19e7a8a..5850b5b 100644
--- a/unit_tests/test_user.py
+++ b/unit_tests/test_user.py
@@ -2,6 +2,33 @@ import pytest
 import mock
 from friendlypins.user import User
 
+def test_user_properties():
+    expected_url = 'https://www.pinterest.com/MyUserName/'
+    expected_firstname = "John"
+    expected_lastname = "Doe"
+    expected_id = 12345678
+    expected_board_count = 32
+    expected_pin_count = 512
+    data = {
+        'url': expected_url,
+        'first_name': expected_firstname,
+        'last_name': expected_lastname,
+        'id': str(expected_id),
+        'counts': {
+            'boards': str(expected_board_count),
+            'pins': str(expected_pin_count)
+        }
+    }
+
+    obj = User(data, "https://pinterest_url/v1", "1234abcd")
+    assert expected_url == obj.url
+    assert expected_firstname == obj.first_name
+    assert expected_lastname == obj.last_name
+    assert expected_id == obj.unique_id
+    assert expected_board_count == obj.num_boards
+    assert expected_pin_count == obj.num_pins
+
+
 def test_get_boards():
     data = {
         "first_name": "John",