Class: EspressoPath::Client
- Inherits:
-
Object
- Object
- EspressoPath::Client
- Includes:
- HTTParty
- Defined in:
- lib/espresso_path/client.rb
Overview
This class is the base client for the API
Instance Method Summary collapse
- #audience ⇒ Object
- #census_tracts ⇒ Object
- #counties ⇒ Object
- #custom_demos ⇒ Object
- #custom_markets ⇒ Object
- #day_part(id) ⇒ Object
- #day_parts ⇒ Object
- #demo_subcategories(id) ⇒ Object
- #demos ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #login(username, password) ⇒ Object
- #map_services(type, level, ids, options = @options) ⇒ Object
- #market(market) ⇒ Object
- #markets ⇒ Object
-
#media_type(id) ⇒ Object
Get the MediaType referenced by the ID # ==== Attributes.
-
#media_types ⇒ Object
Get all the MediaTypes.
- #operators ⇒ Object
- #panel(id) ⇒ Object
- #panel_sets ⇒ Object
-
#panels ⇒ Object
Get all the panels.
- #panels_nearby ⇒ Object
- #plant(id) ⇒ Object
- #plants ⇒ Object
- #states ⇒ Object
Constructor Details
#initialize ⇒ Client
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 login(EspressoPath.configuration.user_name, EspressoPath.configuration.password) end |
Instance Method Details
#audience ⇒ Object
40 41 42 |
# File 'lib/espresso_path/client.rb', line 40 def audience self.class.get('/audience', ) end |
#census_tracts ⇒ Object
44 45 46 |
# File 'lib/espresso_path/client.rb', line 44 def census_tracts self.class.get('/census-tracts', ) end |
#counties ⇒ Object
48 49 50 |
# File 'lib/espresso_path/client.rb', line 48 def counties self.class.get('/counties', ) end |
#custom_demos ⇒ Object
52 53 54 |
# File 'lib/espresso_path/client.rb', line 52 def custom_demos self.class.get('/custom-demos', ) end |
#custom_markets ⇒ Object
56 57 58 |
# File 'lib/espresso_path/client.rb', line 56 def custom_markets self.class.get('/custom-markets', ) 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}", ) end |
#day_parts ⇒ Object
60 61 62 |
# File 'lib/espresso_path/client.rb', line 60 def day_parts self.class.get('/day-parts', ) 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", ) end |
#demos ⇒ Object
68 69 70 |
# File 'lib/espresso_path/client.rb', line 68 def demos self.class.get('/demos/categories', ) 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 login(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'] = { 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, = ) [:query] = { ids: ids} puts .inspect self.class.get("/mapservices/#{type}/#{level}", ) end |
#market(market) ⇒ Object
76 77 78 |
# File 'lib/espresso_path/client.rb', line 76 def market(market) self.class.get("/markets/#{market}", ) end |
#markets ⇒ Object
80 81 82 |
# File 'lib/espresso_path/client.rb', line 80 def markets self.class.get('/markets', ) 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}", ) end |
#media_types ⇒ Object
Get all the MediaTypes
85 86 87 |
# File 'lib/espresso_path/client.rb', line 85 def media_types self.class.get('/media-types', ) end |
#operators ⇒ Object
97 98 99 |
# File 'lib/espresso_path/client.rb', line 97 def operators self.class.get('/operators', ) end |
#panel(id) ⇒ Object
110 111 112 |
# File 'lib/espresso_path/client.rb', line 110 def panel(id) self.class.get("/panels/#{id}", ) end |
#panel_sets ⇒ Object
101 102 103 |
# File 'lib/espresso_path/client.rb', line 101 def panel_sets self.class.get('/panel-sets', ) end |
#panels ⇒ Object
Get all the panels
106 107 108 |
# File 'lib/espresso_path/client.rb', line 106 def panels self.class.get('/panels', ) end |
#panels_nearby ⇒ Object
114 115 116 |
# File 'lib/espresso_path/client.rb', line 114 def panels_nearby self.class.get('/panels/nearby', ) end |
#plant(id) ⇒ Object
122 123 124 |
# File 'lib/espresso_path/client.rb', line 122 def plant(id) self.class.get("/plants/#{id}", ) end |
#plants ⇒ Object
118 119 120 |
# File 'lib/espresso_path/client.rb', line 118 def plants self.class.get('/plants', ) end |
#states ⇒ Object
126 127 128 |
# File 'lib/espresso_path/client.rb', line 126 def states self.class.get('/states', ) end |