Class: EspressoPath::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/espresso_path/client.rb

Overview

This class is the base client for the API

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



11
12
13
14
# File 'lib/espresso_path/client.rb', line 11

def initialize
  self.class.base_uri EspressoPath.configuration.base_url
  (EspressoPath.configuration.user_name, EspressoPath.configuration.password)
end

Instance Method Details

#audienceObject



40
41
42
# File 'lib/espresso_path/client.rb', line 40

def audience
  self.class.get('/audience', @options)
end

#census_tractsObject



44
45
46
# File 'lib/espresso_path/client.rb', line 44

def census_tracts
  self.class.get('/census-tracts', @options)
end

#countiesObject



48
49
50
# File 'lib/espresso_path/client.rb', line 48

def counties
  self.class.get('/counties', @options)
end

#custom_demosObject



52
53
54
# File 'lib/espresso_path/client.rb', line 52

def custom_demos
  self.class.get('/custom-demos', @options)
end

#custom_marketsObject



56
57
58
# File 'lib/espresso_path/client.rb', line 56

def custom_markets
  self.class.get('/custom-markets', @options)
end

#day_part(id) ⇒ Object



64
65
66
# File 'lib/espresso_path/client.rb', line 64

def day_part(id)
  self.class.get("/day-parts/#{id}", @options)
end

#day_partsObject



60
61
62
# File 'lib/espresso_path/client.rb', line 60

def day_parts
  self.class.get('/day-parts', @options)
end

#demo_subcategories(id) ⇒ Object



72
73
74
# File 'lib/espresso_path/client.rb', line 72

def demo_subcategories(id)
  self.class.get("/demos/demo_subcategories/#{id}/demo", @options)
end

#demosObject



68
69
70
# File 'lib/espresso_path/client.rb', line 68

def demos
  self.class.get('/demos/categories', @options)
end

#login(username, password) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/espresso_path/client.rb', line 16

def (username, password)
  uri = URI.parse(EspressoPath.configuration.base_url + '/login')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  request = Net::HTTP::Post.new(uri.request_uri)
  request.set_form_data(username: username, password: password)
  response = http.request(request)
  body = JSON.parse(response.body)
  @access_token = body['access_token']
  @options = {
    headers: {
      Authorization: "Bearer #{@access_token}"
    },

  }
end

#map_services(type, level, ids, options = @options) ⇒ Object



34
35
36
37
38
# File 'lib/espresso_path/client.rb', line 34

def map_services(type, level, ids, options = @options)
  options[:query] = { ids: ids}
  puts options.inspect
  self.class.get("/mapservices/#{type}/#{level}", @options)
end

#market(market) ⇒ Object



76
77
78
# File 'lib/espresso_path/client.rb', line 76

def market(market)
  self.class.get("/markets/#{market}", @options)
end

#marketsObject



80
81
82
# File 'lib/espresso_path/client.rb', line 80

def markets
  self.class.get('/markets', @options)
end

#media_type(id) ⇒ Object

Get the MediaType referenced by the ID # ==== Attributes

  • id - The id of the object you wish to retrieve.



93
94
95
# File 'lib/espresso_path/client.rb', line 93

def media_type(id)
  self.class.get("/media-types/#{id}", @options)
end

#media_typesObject

Get all the MediaTypes



85
86
87
# File 'lib/espresso_path/client.rb', line 85

def media_types
  self.class.get('/media-types', @options)
end

#operatorsObject



97
98
99
# File 'lib/espresso_path/client.rb', line 97

def operators
  self.class.get('/operators', @options)
end

#panel(id) ⇒ Object



110
111
112
# File 'lib/espresso_path/client.rb', line 110

def panel(id)
  self.class.get("/panels/#{id}", @options)
end

#panel_setsObject



101
102
103
# File 'lib/espresso_path/client.rb', line 101

def panel_sets
  self.class.get('/panel-sets', @options)
end

#panelsObject

Get all the panels



106
107
108
# File 'lib/espresso_path/client.rb', line 106

def panels
  self.class.get('/panels', @options)
end

#panels_nearbyObject



114
115
116
# File 'lib/espresso_path/client.rb', line 114

def panels_nearby
  self.class.get('/panels/nearby', @options)
end

#plant(id) ⇒ Object



122
123
124
# File 'lib/espresso_path/client.rb', line 122

def plant(id)
  self.class.get("/plants/#{id}", @options)
end

#plantsObject



118
119
120
# File 'lib/espresso_path/client.rb', line 118

def plants
  self.class.get('/plants', @options)
end

#statesObject



126
127
128
# File 'lib/espresso_path/client.rb', line 126

def states
  self.class.get('/states', @options)
end