Class: Brandspotter::Client

Inherits:
Object show all
Defined in:
lib/brandspotter/client.rb,
lib/brandspotter/client/jobs.rb,
lib/brandspotter/client/endpoints.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

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_tokenObject

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

#locationsObject



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

#subscriptionsObject



4
5
6
# File 'lib/brandspotter/client/jobs.rb', line 4

def subscriptions
  get_request configure_payload('/subscriptions')
end