Class: Socialfred::Requester
- Inherits:
-
Object
- Object
- Socialfred::Requester
- Defined in:
- lib/socialfred/requester.rb
Constant Summary collapse
- CONTENT_TYPE =
'application/json'
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_url ⇒ Object
readonly
Returns the value of attribute api_url.
Instance Method Summary collapse
- #delete(endpoint) ⇒ Object
- #get(endpoint, parameters = nil) ⇒ Object
-
#initialize(api_key, api_url) ⇒ Requester
constructor
A new instance of Requester.
- #post(endpoint, parameters = nil) ⇒ Object
- #put(endpoint, parameters = nil) ⇒ Object
Constructor Details
#initialize(api_key, api_url) ⇒ Requester
Returns a new instance of Requester.
11 12 13 14 |
# File 'lib/socialfred/requester.rb', line 11 def initialize(api_key, api_url) @api_key = api_key @api_url = api_url end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/socialfred/requester.rb', line 7 def api_key @api_key end |
#api_url ⇒ Object (readonly)
Returns the value of attribute api_url.
7 8 9 |
# File 'lib/socialfred/requester.rb', line 7 def api_url @api_url end |
Instance Method Details
#delete(endpoint) ⇒ Object
36 37 38 39 40 |
# File 'lib/socialfred/requester.rb', line 36 def delete(endpoint) conn.delete(endpoint) do |req| req.headers[:content_type] = CONTENT_TYPE end end |
#get(endpoint, parameters = nil) ⇒ Object
16 17 18 19 20 |
# File 'lib/socialfred/requester.rb', line 16 def get(endpoint, parameters = nil) conn.get(endpoint, parameters) do |req| req.headers[:content_type] = CONTENT_TYPE end end |
#post(endpoint, parameters = nil) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/socialfred/requester.rb', line 22 def post(endpoint, parameters = nil) conn.post(endpoint) do |req| req.headers[:content_type] = CONTENT_TYPE req.body = JSON.generate(parameters) end end |
#put(endpoint, parameters = nil) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/socialfred/requester.rb', line 29 def put(endpoint, parameters = nil) conn.put(endpoint) do |req| req.headers[:content_type] = CONTENT_TYPE req.body = JSON.generate(parameters) end end |