Class: Gifster::Client
- Inherits:
-
Object
- Object
- Gifster::Client
- Defined in:
- lib/gifster/client.rb
Constant Summary collapse
- BASE_URL =
"http://api.giphy.com"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
- #search(query, limit, offset) ⇒ Object
- #trending(limit, offset) ⇒ Object
Constructor Details
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/gifster/client.rb', line 8 def api_key @api_key end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
8 9 10 |
# File 'lib/gifster/client.rb', line 8 def connection @connection end |
Instance Method Details
#search(query, limit, offset) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/gifster/client.rb', line 15 def search(query, limit, offset) response = connection.get do |req| req.url "/v1/gifs/search" req.headers["Accepts"] = "application/json" req.params['api_key'] = api_key req.params['q'] = query req.params['limit'] = limit req.params['offset'] = offset end JSON.parse(response.body)["data"] end |
#trending(limit, offset) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/gifster/client.rb', line 27 def trending(limit, offset) response = connection.get do |req| req.url "/v1/gifs/trending" req.headers["Accepts"] = "application/json" req.params['api_key'] = api_key req.params['offset'] = offset end JSON.parse(response.body)["data"] end |