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(daypart_ids, panel_ids, market_id, population_base, opts = {}) ⇒ Object
Get Audience.
-
#audience_home(daypart_id, panel_ids, market_id, population_base, reporting_level, opts = {}) ⇒ Object
Get Home Audience.
-
#census_tract(id) ⇒ Object
Gets specified Census Tract # ==== Attributes.
-
#census_tracts ⇒ Object
Gets all Census Tracts.
- #counties ⇒ Object
-
#create_custom_demo(name, audience = 'company', opts = {}) ⇒ Object
Create a Custom Demographic # ==== Attributes.
- #custom_demo(id) ⇒ Object
- #custom_demos ⇒ Object
- #custom_markets ⇒ Object
- #day_part(id) ⇒ Object
- #day_parts ⇒ Object
-
#delete_custom_demo(id) ⇒ Object
Delete a Custom Demographic # ==== Attributes.
- #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
-
#update_custom_demo(id, opts = {}) ⇒ Object
Update a Custom Demographic # ==== Attributes.
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(daypart_ids, panel_ids, market_id, population_base, opts = {}) ⇒ Object
Get Audience
# ==== Attributes
-
daypart_ids- REQUIRED - Comma-separated list of daypart IDs. -
demo_ids- Optional - Comma-separated list of demo IDs. Either this or custom_demo_ids must be provided. -
custom_demo_ids- Optional - Comma-separated list of custom demo IDs. Either this or demo_ids must be provided. -
panel_ids- REQUIRED - Comma-separated list of panel IDs. -
market_id- REQUIRED - Market ID to get information for. -
population_base- REQUIRED - Base population.
47 48 49 50 51 52 |
# File 'lib/espresso_path/client.rb', line 47 def audience(daypart_ids, panel_ids, market_id, population_base, opts ={}) = [:query] = { daypart_ids: daypart_ids, panel_ids: panel_ids, market_id: market_id, population_base: population_base }.merge(opts) self.class.get('/audience', ) end |
#audience_home(daypart_id, panel_ids, market_id, population_base, reporting_level, opts = {}) ⇒ Object
Get Home Audience
# ==== Attributes
-
daypart_id- REQUIRED - Daypart ID to look for. -
demo_id- Optional - Comma-separated list of demo IDs. Either this or custom_demo_ids must be provided. -
custom_demo_id- Optional - Comma-separated list of custom demo IDs. Either this or demo_ids must be provided. -
panel_ids- REQUIRED - Comma-separated list of panel IDs. -
market_id- REQUIRED - Market ID to get information for. -
population_base- REQUIRED - Base population. -
reporting_level- REQUIRED - Geo level to get homes for.
64 65 66 67 68 69 70 |
# File 'lib/espresso_path/client.rb', line 64 def audience_home(daypart_id, panel_ids, market_id, population_base, reporting_level, opts ={}) = [:query] = { daypart_id: daypart_id, panel_ids: panel_ids, market_id: market_id, reporting_level: reporting_level, population_base: population_base }.merge(opts) self.class.get('/audience/homes', ) end |
#census_tract(id) ⇒ Object
Gets specified Census Tract # ==== Attributes
-
id- Required - Census TractID
81 82 83 |
# File 'lib/espresso_path/client.rb', line 81 def census_tract(id) self.class.get("/census-tracts/#{id}", ) end |
#census_tracts ⇒ Object
Gets all Census Tracts
73 74 75 |
# File 'lib/espresso_path/client.rb', line 73 def census_tracts self.class.get('/census-tracts', ) end |
#counties ⇒ Object
85 86 87 |
# File 'lib/espresso_path/client.rb', line 85 def counties self.class.get('/counties', ) end |
#create_custom_demo(name, audience = 'company', opts = {}) ⇒ Object
Create a Custom Demographic # ==== Attributes
-
name- Required - The name of demographic -
age_min- Optional - The minimum age in the custom demo -
age_max- Optional - The maximum age in the custom demo -
hhinc_min- Optional - The minimum household income in the custom demo -
hhinc_max- Optional - The maximum household income in the custom demo -
races- Optional - The races included in the custom demo. Supported values are white, black, amerindian, asian, pacific, other -
sex- Optional - The sex in the custom demo -
employed- Optional - The employment status in the custom demo -
audience- Required - Who can use this custom demo
109 110 111 112 113 |
# File 'lib/espresso_path/client.rb', line 109 def create_custom_demo(name, audience = 'company', opts = {}) = [:query] = { name: name, audience: audience }.merge(opts) self.class.post('/custom-demos', ) end |
#custom_demo(id) ⇒ Object
93 94 95 |
# File 'lib/espresso_path/client.rb', line 93 def custom_demo(id) self.class.get("/custom-demos/#{id}", ) end |
#custom_demos ⇒ Object
89 90 91 |
# File 'lib/espresso_path/client.rb', line 89 def custom_demos self.class.get('/custom-demos', ) end |
#custom_markets ⇒ Object
142 143 144 |
# File 'lib/espresso_path/client.rb', line 142 def custom_markets self.class.get('/custom-markets', ) end |
#day_part(id) ⇒ Object
150 151 152 |
# File 'lib/espresso_path/client.rb', line 150 def day_part(id) self.class.get("/day-parts/#{id}", ) end |
#day_parts ⇒ Object
146 147 148 |
# File 'lib/espresso_path/client.rb', line 146 def day_parts self.class.get('/day-parts', ) end |
#delete_custom_demo(id) ⇒ Object
Delete a Custom Demographic # ==== Attributes
-
id- Required - Custom Demographic ID
138 139 140 |
# File 'lib/espresso_path/client.rb', line 138 def delete_custom_demo(id) self.class.delete("/custom-demos/#{id}", ) end |
#demo_subcategories(id) ⇒ Object
158 159 160 |
# File 'lib/espresso_path/client.rb', line 158 def demo_subcategories(id) self.class.get("/demos/demo_subcategories/#{id}/demo", ) end |
#demos ⇒ Object
154 155 156 |
# File 'lib/espresso_path/client.rb', line 154 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 |
# 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
33 34 35 36 |
# File 'lib/espresso_path/client.rb', line 33 def map_services(type, level, ids, = ) [:query] = { ids: ids } self.class.get("/mapservices/#{type}/#{level}", ) end |
#market(market) ⇒ Object
162 163 164 |
# File 'lib/espresso_path/client.rb', line 162 def market(market) self.class.get("/markets/#{market}", ) end |
#markets ⇒ Object
166 167 168 |
# File 'lib/espresso_path/client.rb', line 166 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.
179 180 181 |
# File 'lib/espresso_path/client.rb', line 179 def media_type(id) self.class.get("/media-types/#{id}", ) end |
#media_types ⇒ Object
Get all the MediaTypes
171 172 173 |
# File 'lib/espresso_path/client.rb', line 171 def media_types self.class.get('/media-types', ) end |
#operators ⇒ Object
183 184 185 |
# File 'lib/espresso_path/client.rb', line 183 def operators self.class.get('/operators', ) end |
#panel(id) ⇒ Object
196 197 198 |
# File 'lib/espresso_path/client.rb', line 196 def panel(id) self.class.get("/panels/#{id}", ) end |
#panel_sets ⇒ Object
187 188 189 |
# File 'lib/espresso_path/client.rb', line 187 def panel_sets self.class.get('/panel-sets', ) end |
#panels ⇒ Object
Get all the panels
192 193 194 |
# File 'lib/espresso_path/client.rb', line 192 def panels self.class.get('/panels', ) end |
#panels_nearby ⇒ Object
200 201 202 |
# File 'lib/espresso_path/client.rb', line 200 def panels_nearby self.class.get('/panels/nearby', ) end |
#plant(id) ⇒ Object
208 209 210 |
# File 'lib/espresso_path/client.rb', line 208 def plant(id) self.class.get("/plants/#{id}", ) end |
#plants ⇒ Object
204 205 206 |
# File 'lib/espresso_path/client.rb', line 204 def plants self.class.get('/plants', ) end |
#states ⇒ Object
212 213 214 |
# File 'lib/espresso_path/client.rb', line 212 def states self.class.get('/states', ) end |
#update_custom_demo(id, opts = {}) ⇒ Object
Update a Custom Demographic # ==== Attributes
-
id- Required - Custom Demographic ID -
name- Optional - The name of demographic -
age_min- Optional - The minimum age in the custom demo -
age_max- Optional - The maximum age in the custom demo -
hhinc_min- Optional - The minimum household income in the custom demo -
hhinc_max- Optional - The maximum household income in the custom demo -
races- Optional - The races included in the custom demo. Supported values are white, black, amerindian, asian, pacific, other -
sex- Optional - The sex in the custom demo -
employed- Optional - The employment status in the custom demo -
audience- Optional - Who can use this custom demo
128 129 130 131 132 |
# File 'lib/espresso_path/client.rb', line 128 def update_custom_demo(id, opts = {}) = [:query] = opts self.class.put("/custom-demos/#{id}", ) end |