Class: Zootool::ZootoolApi
- Inherits:
-
Object
- Object
- Zootool::ZootoolApi
- Includes:
- HTTParty
- Defined in:
- lib/zootool/zootool_api.rb
Overview
A wrapper that provides access to the Zootool API.
Instance Attribute Summary collapse
-
#api_key ⇒ Object
The API key for your Zootool application.
Instance Method Summary collapse
-
#initialize(api_key) ⇒ ZootoolApi
constructor
Initializes the ZootoolApi object for making requests.
-
#item(uid) ⇒ Object
Provides a simple way to get a specific item by its uid.
-
#items ⇒ Object
Provides a simple way to get items.
-
#request(path) ⇒ Object
Makes a request to the specified path and returns a Hash containing the result of the HTTP request.
-
#users(username = nil) ⇒ Object
Provides a simple way to get Zootool items and info for users.
Constructor Details
#initialize(api_key) ⇒ ZootoolApi
Initializes the ZootoolApi object for making requests. You must specify your Zootool Application API key for requests to return data successfully.
Example:
api = Zootool::ZootoolApi.new('your_api_key_goes_here')
23 24 25 |
# File 'lib/zootool/zootool_api.rb', line 23 def initialize api_key @api_key = api_key end |
Instance Attribute Details
#api_key ⇒ Object
The API key for your Zootool application. Set when creating a new ZootoolApi.
14 15 16 |
# File 'lib/zootool/zootool_api.rb', line 14 def api_key @api_key end |
Instance Method Details
#item(uid) ⇒ Object
Provides a simple way to get a specific item by its uid. This is just shorthand for the longer api.items.info method.
Example:
api = Zootool::ZootoolApi.new('apikey')
item_by_uid = api.item('1kf7s')
51 52 53 |
# File 'lib/zootool/zootool_api.rb', line 51 def item uid self.items.info(uid) end |
#items ⇒ Object
Provides a simple way to get items.
Example:
api = Zootool::ZootoolApi.new('apikey')
items = api.items.popular('week')
item_by_uid = api.items.info('1kf7s')
63 64 65 |
# File 'lib/zootool/zootool_api.rb', line 63 def items Zootool::ItemsQuery.new(self) end |
#request(path) ⇒ Object
Makes a request to the specified path and returns a Hash containing the result of the HTTP request.
70 71 72 73 |
# File 'lib/zootool/zootool_api.rb', line 70 def request(path) url = "#{Zootool::API_URL}#{path}&apikey=#{@api_key}" self.class.get(url).parsed_response end |
#users(username = nil) ⇒ Object
Provides a simple way to get Zootool items and info for users.
Returns a UsersQuery that provides methods to easily access the items and other info for users. The methods of the returned UsersQuery return a
Example:
api = Zootool::ZootoolApi.new('your_api_key')
user_items = api.users('rmauer').items
all_items = api.users.items
all_paged = api.users.items(:limit => 5, :offset => 10)
39 40 41 |
# File 'lib/zootool/zootool_api.rb', line 39 def users username=nil Zootool::UsersQuery.new(self,username) end |