Class: EspressoPath::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/espresso_path/client.rb

Instance Method Summary collapse

Constructor Details

#initializeClient

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
  (EspressoPath.configuration.user_name, EspressoPath.configuration.password)
end

Instance Method Details

#audienceObject



31
32
33
# File 'lib/espresso_path/client.rb', line 31

def audience
  self.class.get('/audience', @options)
end

#countiesObject



39
40
41
# File 'lib/espresso_path/client.rb', line 39

def counties
  self.class.get('/counties', @options)
end

#custom_demosObject



43
44
45
# File 'lib/espresso_path/client.rb', line 43

def custom_demos
  self.class.get('/custom-demos', @options)
end

#day_partsObject



35
36
37
# File 'lib/espresso_path/client.rb', line 35

def day_parts
  self.class.get('/day-parts', @options)
end

#demo_categoriesObject



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 (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

#marketsObject



59
60
61
# File 'lib/espresso_path/client.rb', line 59

def markets
  self.class.get('/markets', @options)
end

#media_typesObject



47
48
49
# File 'lib/espresso_path/client.rb', line 47

def media_types
  self.class.get('/media-types', @options)
end

#operatorsObject



51
52
53
# File 'lib/espresso_path/client.rb', line 51

def operators
  self.class.get('/operators', @options)
end

#panelsObject



67
68
69
# File 'lib/espresso_path/client.rb', line 67

def panels
  self.class.get('/panels', @options)
end

#plantsObject



55
56
57
# File 'lib/espresso_path/client.rb', line 55

def plants
  self.class.get('/plants', @options)
end

#statesObject



75
76
77
# File 'lib/espresso_path/client.rb', line 75

def states
  self.class.get('/states', @options)
end