Skip to content
This repository has been archived by the owner on Aug 24, 2023. It is now read-only.

Required Client-ID Header for Kraken API calls #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/twitch/adapters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module Twitch
module Adapters
DEFAULT_ADAPTER = Twitch::Adapters::HTTPartyAdapter

def get_adapter(adapter, default_adapter = DEFAULT_ADAPTER)
begin
Twitch::Adapters.const_defined?(adapter.to_s)
Expand All @@ -15,4 +15,4 @@ def get_adapter(adapter, default_adapter = DEFAULT_ADAPTER)
end
end
end
end
end
14 changes: 7 additions & 7 deletions lib/twitch/adapters/base_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
module Twitch
module Adapters
class BaseAdapter
def self.get(url)
request(:get, url)
def self.get(url, options = {})
request(:get, url, options)
end

def self.post(url, options)
def self.post(url, options = {})
request(:post, url, options)
end

def self.put(url, options)
def self.put(url, options = {})
request(:put, url, options)
end

def self.delete(url)
request(:delete, url)
def self.delete(url, options = {})
request(:delete, url, options)
end

def self.request(method, url, options)
def self.request(method, url, options = {})
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/twitch/adapters/httparty_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
module Twitch
module Adapters
class HTTPartyAdapter < BaseAdapter
def self.request(method, url, options={})

def self.request(method, url, options = {})
res = HTTParty.send(method, url, options)
{:body => res, :response => res.code}
end
Expand Down
8 changes: 4 additions & 4 deletions lib/twitch/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class Client
include Twitch::Adapters

def initialize(options = {})
@client_id = options[:client_id] || nil
@secret_key = options[:secret_key] || nil
@redirect_uri = options[:redirect_uri] || nil
@scope = options[:scope] || nil
@client_id = options[:client_id] || ""
@secret_key = options[:secret_key] || ""
@redirect_uri = options[:redirect_uri] || ""
@scope = options[:scope] || []
@access_token = options[:access_token] || nil

@adapter = get_adapter(options[:adapter] || nil)
Expand Down
21 changes: 14 additions & 7 deletions lib/twitch/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,30 @@ def build_query_string(options)
end

def get(url)
@adapter.get(url)
@adapter.get(url, :headers => {
'Client-ID' => @client_id
})
end

def post(url, data)
@adapter.post(url, :body => data)
@adapter.post(url, :body => data, :headers => {
'Client-ID' => @client_id
})
end

def put(url, data={})
@adapter.put(url, :body => data, :headers => {
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Api-Version' => '2.2'
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Api-Version' => '2.2',
'Client-ID' => @client_id
})
end

def delete(url)
@adapter.delete(url)
@adapter.delete(url, :headers => {
'Client-ID' => @client_id
})
end
end
end
12 changes: 12 additions & 0 deletions spec/helpers/debug_httparty_adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'httparty'

module Twitch
module Adapters
class DebugHTTPartyAdapter < BaseAdapter
def self.request(method, url, options={})
res = HTTParty.send(method, url, options.merge(:debug_output => $debug_output))
{:body => res, :response => res.code}
end
end
end
end
20 changes: 20 additions & 0 deletions spec/helpers/open_uri_adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'open-uri'

module Twitch
module Adapters
class OpenURIAdapter < BaseAdapter
def self.request(method, url, options={})
if (method == :get)
ret = {}

open(url) do |io|
ret[:body] = JSON.parse(io.read)
ret[:response] = io.status.first.to_i
end

ret
end
end
end # class OpenURIAdapter
end # module Adapters
end # module Twitch
Loading