Sha256: 4e1a6b38ea5ce8c6cfcc265503143de37e8e2e457ccd018e20f9ad2c8929a43b

Contents?: true

Size: 1.7 KB

Versions: 4

Compression:

Stored size: 1.7 KB

Contents

require 'logger'
require 'httparty'
require 'json'

module EspressoPath
  class GeoPath
    include HTTParty
    #base_uri 'insights-api.geopath.org'

    def login
      self.class.base_uri EspressoPath.configuration.base_url
      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 => EspressoPath.configuration.user_name, :password => EspressoPath.configuration.password })

      response = http.request(request)
      body = JSON.parse(response.body)

      @access_token = body["access_token"]

      @options = {
          headers: {
              "Authorization"=> "Bearer #{@access_token}"
          }
      }
    end

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

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

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

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

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

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

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

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

    def market(market)
      self.class.get("/markets/#{market}", @options)
    end

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

    def demo_categories
      self.class.get("/demos/categories", @options)
    end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
espresso_path-0.1.4 lib/espresso_path/geo_path.rb
espresso_path-0.1.3 lib/espresso_path/geo_path.rb
espresso_path-0.1.2 lib/espresso_path/geo_path.rb
espresso_path-0.1.0 lib/espresso_path/geo_path.rb