class Hurriyet::Service::Base

Constants

ALLOWED_PARAMETERS

Attributes

client[RW]

Public Class Methods

new(client) click to toggle source
# File lib/hurriyet/service/base.rb, line 10
def initialize(client)
  @client = client
  @conn = Faraday.new(url: 'https://api.hurriyet.com.tr', headers: { apikey: @client.apikey })
end

Public Instance Methods

allowed?(key) click to toggle source
# File lib/hurriyet/service/base.rb, line 40
def allowed?(key)
  ALLOWED_PARAMETERS.include? key
end
execute(endpoint, options = {}) click to toggle source
# File lib/hurriyet/service/base.rb, line 15
def execute(endpoint, options = {})
  @options  = options
  @endpoint = endpoint
  make_call
end
make_call() click to toggle source
# File lib/hurriyet/service/base.rb, line 21
def make_call
  resp = @conn.get(url)
  JSON.parse(resp.body)
end
param_string() click to toggle source
# File lib/hurriyet/service/base.rb, line 30
def param_string
  string = ''
  @options.each_with_index do |(key, value), index|
    raise unless allowed?(key)
    prefix = index == 0 ? '?' : '&'
    string << "#{prefix}$#{key}=#{value}"
  end
  string
end
url() click to toggle source
# File lib/hurriyet/service/base.rb, line 26
def url
  "/#{version}/#{@endpoint}#{param_string}"
end
version() click to toggle source
# File lib/hurriyet/service/base.rb, line 44
def version
  'v1'
end