Class: Brandspotter::Client
- Defined in:
- lib/brandspotter/client.rb,
lib/brandspotter/client/jobs.rb,
lib/brandspotter/client/endpoints.rb
Instance Attribute Summary collapse
-
#user_token ⇒ Object
Returns the value of attribute user_token.
Instance Method Summary collapse
- #base_uri(path = '/') ⇒ Object
- #configure_payload(path, opts = {}) ⇒ Object
- #create_location(opts = {}) ⇒ Object
- #create_subscription(opts = {}) ⇒ Object
- #delete_request(path) ⇒ Object
- #destroy_location(id) ⇒ Object
- #destroy_subscription(id) ⇒ Object
- #find_location(id) ⇒ Object
- #find_subscription(id) ⇒ Object
- #get_request(url) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #locations ⇒ Object
- #post_request(path, opts) ⇒ Object
- #subscriptions ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/brandspotter/client.rb', line 8 def initialize @user_token = Brandspotter.configuration.user_token end |
Instance Attribute Details
#user_token ⇒ Object
Returns the value of attribute user_token.
6 7 8 |
# File 'lib/brandspotter/client.rb', line 6 def user_token @user_token end |
Instance Method Details
#base_uri(path = '/') ⇒ Object
3 4 5 |
# File 'lib/brandspotter/client/endpoints.rb', line 3 def base_uri(path='/') "http://brandspotter.herokuapp.com/api#{path}?user_token=#{self.user_token}&" end |
#configure_payload(path, opts = {}) ⇒ Object
7 8 9 |
# File 'lib/brandspotter/client/endpoints.rb', line 7 def configure_payload(path, opts={}) base_uri(path) + opts.to_params end |
#create_location(opts = {}) ⇒ Object
29 30 31 32 |
# File 'lib/brandspotter/client/jobs.rb', line 29 def create_location(opts={}) opts.assert_valid_keys(:location, :instagram_location_id) post_request '/locations', opts end |
#create_subscription(opts = {}) ⇒ Object
12 13 14 15 |
# File 'lib/brandspotter/client/jobs.rb', line 12 def create_subscription(opts={}) opts.assert_valid_keys(:hashtag) post_request '/subscriptions', opts end |
#delete_request(path) ⇒ Object
19 20 21 |
# File 'lib/brandspotter/client/endpoints.rb', line 19 def delete_request(path) JSON.parse RestClient::Request.execute(method: :delete, url: base_uri(path)) end |
#destroy_location(id) ⇒ Object
34 35 36 |
# File 'lib/brandspotter/client/jobs.rb', line 34 def destroy_location(id) delete_request "/locations/#{id}" end |
#destroy_subscription(id) ⇒ Object
17 18 19 |
# File 'lib/brandspotter/client/jobs.rb', line 17 def destroy_subscription(id) delete_request "/subscriptions/#{id}" end |
#find_location(id) ⇒ Object
25 26 27 |
# File 'lib/brandspotter/client/jobs.rb', line 25 def find_location(id) get_request configure_payload("/locations/#{id}") end |
#find_subscription(id) ⇒ Object
8 9 10 |
# File 'lib/brandspotter/client/jobs.rb', line 8 def find_subscription(id) get_request configure_payload("/subscriptions/#{id}") end |
#get_request(url) ⇒ Object
11 12 13 |
# File 'lib/brandspotter/client/endpoints.rb', line 11 def get_request(url) JSON.parse RestClient::Request.execute(method: :get, url: url) end |
#locations ⇒ Object
21 22 23 |
# File 'lib/brandspotter/client/jobs.rb', line 21 def locations get_request configure_payload('/locations') end |
#post_request(path, opts) ⇒ Object
15 16 17 |
# File 'lib/brandspotter/client/endpoints.rb', line 15 def post_request(path, opts) JSON.parse RestClient.post(base_uri(path), opts) end |
#subscriptions ⇒ Object
4 5 6 |
# File 'lib/brandspotter/client/jobs.rb', line 4 def subscriptions get_request configure_payload('/subscriptions') end |