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
Get the Demo Subcategories referenced by the ID # ==== Attributes.
- #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(params = {}, opts = { full: true, page: 1, page_length: 100}) ⇒ 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 ={}) = @options [: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 ={}) = @options [: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}", @options) 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', @options) end |
#counties ⇒ Object
85 86 87 |
# File 'lib/espresso_path/client.rb', line 85 def counties self.class.get('/counties', @options) 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 = {}) = @options [: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}", @options) end |
#custom_demos ⇒ Object
89 90 91 |
# File 'lib/espresso_path/client.rb', line 89 def custom_demos self.class.get('/custom-demos', @options) end |
#custom_markets ⇒ Object
142 143 144 |
# File 'lib/espresso_path/client.rb', line 142 def custom_markets self.class.get('/custom-markets', @options) 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}", @options) end |
#day_parts ⇒ Object
146 147 148 |
# File 'lib/espresso_path/client.rb', line 146 def day_parts self.class.get('/day-parts', @options) 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}", @options) end |
#demo_subcategories(id) ⇒ Object
Get the Demo Subcategories referenced by the ID # ==== Attributes
-
id
- The id of the object you wish to retrieve.
162 163 164 |
# File 'lib/espresso_path/client.rb', line 162 def demo_subcategories(id) self.class.get("/demos/subcategories/#{id}/demos", @options) end |
#demos ⇒ Object
154 155 156 |
# File 'lib/espresso_path/client.rb', line 154 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 |
# 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'] @options = { 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, = @options) [:query] = { ids: ids } self.class.get("/mapservices/#{type}/#{level}", @options) end |
#market(market) ⇒ Object
166 167 168 |
# File 'lib/espresso_path/client.rb', line 166 def market(market) self.class.get("/markets/#{market}", @options) end |
#markets ⇒ Object
170 171 172 |
# File 'lib/espresso_path/client.rb', line 170 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.
183 184 185 |
# File 'lib/espresso_path/client.rb', line 183 def media_type(id) self.class.get("/media-types/#{id}", @options) end |
#media_types ⇒ Object
Get all the MediaTypes
175 176 177 |
# File 'lib/espresso_path/client.rb', line 175 def media_types self.class.get('/media-types', @options) end |
#operators ⇒ Object
187 188 189 |
# File 'lib/espresso_path/client.rb', line 187 def operators self.class.get('/operators', @options) end |
#panel(id) ⇒ Object
217 218 219 |
# File 'lib/espresso_path/client.rb', line 217 def panel(id) self.class.get("/panels/#{id}", @options) end |
#panel_sets ⇒ Object
191 192 193 |
# File 'lib/espresso_path/client.rb', line 191 def panel_sets self.class.get('/panel-sets', @options) end |
#panels(params = {}, opts = { full: true, page: 1, page_length: 100}) ⇒ Object
Get all the panels
# ==== Attributes
Required - One of markets, counties, states
-
markets
- Optional - Market uuid -
counties
- Optional - Counties FIPS -
states
- Optional - State FIPS -
order_by
- Optional - Columns to order output by (?order_by=operator+asc,geopath_panel_id+desc) -
page
- Required - page number -
page_len
- Optional - Number of items per page. Only used if param page is present (Required even though the docs say it is optional) -
filters
- Optional - List of filter names -
operator_name
- Optional - (If listed in filters) List of operator names to filter by -
plant_unit_id
- Optional - (If listed in filters) List of plant unit ids to filter by -
structure_id
- Optional - (If listed in filters) List of structure ids to filter by -
media_type_name
- Optional -(If listed in filters) List of media_type_names ids to filter by
211 212 213 214 215 |
# File 'lib/espresso_path/client.rb', line 211 def panels(params = {}, opts = { full: true, page: 1, page_length: 100}) = @options [:query] = params.merge(opts) self.class.get('/panels', @options) end |
#panels_nearby ⇒ Object
221 222 223 |
# File 'lib/espresso_path/client.rb', line 221 def panels_nearby self.class.get('/panels/nearby', @options) end |
#plant(id) ⇒ Object
229 230 231 |
# File 'lib/espresso_path/client.rb', line 229 def plant(id) self.class.get("/plants/#{id}", @options) end |
#plants ⇒ Object
225 226 227 |
# File 'lib/espresso_path/client.rb', line 225 def plants self.class.get('/plants', @options) end |
#states ⇒ Object
233 234 235 |
# File 'lib/espresso_path/client.rb', line 233 def states self.class.get('/states', @options) 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 = {}) = @options [:query] = opts self.class.put("/custom-demos/#{id}", ) end |