class EspressoPath::Client
This class is the base client for the API
Public Class Methods
# 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
Public Instance Methods
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.
# File lib/espresso_path/client.rb, line 47 def audience(daypart_ids, panel_ids, market_id, population_base, opts ={}) options = @options options[:query] = { daypart_ids: daypart_ids, panel_ids: panel_ids, market_id: market_id, population_base: population_base }.merge(opts) self.class.get('/audience', options) end
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.
# File lib/espresso_path/client.rb, line 64 def audience_home(daypart_id, panel_ids, market_id, population_base, reporting_level, opts ={}) options = @options 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', options) end
Gets specified Census Tract # ==== Attributes
-
id
- Required - Census TractID
# File lib/espresso_path/client.rb, line 81 def census_tract(id) self.class.get("/census-tracts/#{id}", @options) end
Gets all Census Tracts
# File lib/espresso_path/client.rb, line 73 def census_tracts self.class.get('/census-tracts', @options) end
# File lib/espresso_path/client.rb, line 85 def counties self.class.get('/counties', @options) end
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
# File lib/espresso_path/client.rb, line 109 def create_custom_demo(name, audience = 'company', opts = {}) options = @options options[:query] = { name: name, audience: audience }.merge(opts) self.class.post('/custom-demos', options) end
# File lib/espresso_path/client.rb, line 93 def custom_demo(id) self.class.get("/custom-demos/#{id}", @options) end
# File lib/espresso_path/client.rb, line 89 def custom_demos self.class.get('/custom-demos', @options) end
# File lib/espresso_path/client.rb, line 142 def custom_markets self.class.get('/custom-markets', @options) end
# File lib/espresso_path/client.rb, line 150 def day_part(id) self.class.get("/day-parts/#{id}", @options) end
# File lib/espresso_path/client.rb, line 146 def day_parts self.class.get('/day-parts', @options) end
Delete a Custom Demographic # ==== Attributes
-
id
- Required - Custom Demographic ID
# File lib/espresso_path/client.rb, line 138 def delete_custom_demo(id) self.class.delete("/custom-demos/#{id}", @options) end
Get the Demo Subcategories referenced by the ID # ==== Attributes
-
id
- The id of the object you wish to retrieve.
# File lib/espresso_path/client.rb, line 162 def demo_subcategories(id) self.class.get("/demos/subcategories/#{id}/demos", @options) end
# File lib/espresso_path/client.rb, line 154 def demos self.class.get('/demos/categories', @options) end
# 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
# File lib/espresso_path/client.rb, line 33 def map_services(type, level, ids, options = @options) options[:query] = { ids: ids } self.class.get("/mapservices/#{type}/#{level}", @options) end
# File lib/espresso_path/client.rb, line 166 def market(market) self.class.get("/markets/#{market}", @options) end
# File lib/espresso_path/client.rb, line 170 def markets self.class.get('/markets', @options) end
Get the MediaType referenced by the ID # ==== Attributes
-
id
- The id of the object you wish to retrieve.
# File lib/espresso_path/client.rb, line 183 def media_type(id) self.class.get("/media-types/#{id}", @options) end
Get all the MediaTypes
# File lib/espresso_path/client.rb, line 175 def media_types self.class.get('/media-types', @options) end
# File lib/espresso_path/client.rb, line 187 def operators self.class.get('/operators', @options) end
# File lib/espresso_path/client.rb, line 217 def panel(id) self.class.get("/panels/#{id}", @options) end
# File lib/espresso_path/client.rb, line 191 def panel_sets self.class.get('/panel-sets', @options) end
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
# File lib/espresso_path/client.rb, line 211 def panels(params = {}, opts = { full: true, page: 1, page_length: 100}) options = @options options[:query] = params.merge(opts) self.class.get('/panels', @options) end
# File lib/espresso_path/client.rb, line 221 def panels_nearby self.class.get('/panels/nearby', @options) end
# File lib/espresso_path/client.rb, line 229 def plant(id) self.class.get("/plants/#{id}", @options) end
# File lib/espresso_path/client.rb, line 225 def plants self.class.get('/plants', @options) end
# File lib/espresso_path/client.rb, line 233 def states self.class.get('/states', @options) end
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
# File lib/espresso_path/client.rb, line 128 def update_custom_demo(id, opts = {}) options = @options options[:query] = opts self.class.put("/custom-demos/#{id}", options) end