Class: EspressoPath::Client
- Inherits:
-
Object
- Object
- EspressoPath::Client
- Includes:
- HTTParty
- Defined in:
- lib/espresso_path/client.rb
Instance Method Summary collapse
- #audience ⇒ Object
- #counties ⇒ Object
- #custom_demos ⇒ Object
- #day_parts ⇒ Object
- #demo_categories ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #login(username, password) ⇒ Object
- #market(market) ⇒ Object
- #markets ⇒ Object
- #media_types ⇒ Object
- #operators ⇒ Object
- #panels ⇒ Object
- #plants ⇒ Object
- #states ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
9 10 11 12 |
# File 'lib/espresso_path/client.rb', line 9 def initialize self.class.base_uri EspressoPath.configuration.base_url login(EspressoPath.configuration.user_name, EspressoPath.configuration.password) end |
Instance Method Details
#audience ⇒ Object
31 32 33 |
# File 'lib/espresso_path/client.rb', line 31 def audience self.class.get('/audience', @options) end |
#counties ⇒ Object
39 40 41 |
# File 'lib/espresso_path/client.rb', line 39 def counties self.class.get('/counties', @options) end |
#custom_demos ⇒ Object
43 44 45 |
# File 'lib/espresso_path/client.rb', line 43 def custom_demos self.class.get('/custom-demos', @options) end |
#day_parts ⇒ Object
35 36 37 |
# File 'lib/espresso_path/client.rb', line 35 def day_parts self.class.get('/day-parts', @options) end |
#demo_categories ⇒ Object
71 72 73 |
# File 'lib/espresso_path/client.rb', line 71 def demo_categories self.class.get('/demos/categories', @options) end |
#login(username, password) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/espresso_path/client.rb', line 14 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 |
#market(market) ⇒ Object
63 64 65 |
# File 'lib/espresso_path/client.rb', line 63 def market(market) self.class.get("/markets/#{market}", @options) end |
#markets ⇒ Object
59 60 61 |
# File 'lib/espresso_path/client.rb', line 59 def markets self.class.get('/markets', @options) end |
#media_types ⇒ Object
47 48 49 |
# File 'lib/espresso_path/client.rb', line 47 def media_types self.class.get('/media-types', @options) end |
#operators ⇒ Object
51 52 53 |
# File 'lib/espresso_path/client.rb', line 51 def operators self.class.get('/operators', @options) end |
#panels ⇒ Object
67 68 69 |
# File 'lib/espresso_path/client.rb', line 67 def panels self.class.get('/panels', @options) end |
#plants ⇒ Object
55 56 57 |
# File 'lib/espresso_path/client.rb', line 55 def plants self.class.get('/plants', @options) end |
#states ⇒ Object
75 76 77 |
# File 'lib/espresso_path/client.rb', line 75 def states self.class.get('/states', @options) end |