Class: AllPlayers::API

Inherits:
Object
  • Object
show all
Includes:
Authentication, Request
Defined in:
lib/allplayers/api.rb

Direct Known Subclasses

Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Authentication

#login, #logout

Methods included from Request

#delete, #get, #post, #put

Constructor Details

#initialize(server = 'https://www.allplayers.com', auth = 'basic', access_token = nil, content_type = 'application/json') ⇒ API

Returns a new instance of API.



13
14
15
16
17
18
19
20
# File 'lib/allplayers/api.rb', line 13

def initialize(server = 'https://www.allplayers.com', auth = 'basic', access_token = nil, content_type = 'application/json')
  @base_uri = server
  if (auth == 'basic')
    extend AllPlayers::Authentication
  end
  @access_token = access_token
  @headers = {:Content_Type => 'application/json'}
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



11
12
13
# File 'lib/allplayers/api.rb', line 11

def logger
  @logger
end

Instance Method Details

#add_headers(header = {}) ⇒ Object

Add header method, preferably use array of symbols, e.g. => ‘RubyClient’.



36
37
38
# File 'lib/allplayers/api.rb', line 36

def add_headers(header = {})
  @headers.merge!(header) unless header.nil?
end

#log(target) ⇒ Object



30
31
32
33
# File 'lib/allplayers/api.rb', line 30

def log(target)
  @log = target
  RestClient.log = target
end

#prepare_access_token(oauth_token, oauth_token_secret, consumer_token, consumer_secret) ⇒ Object

Exchange your oauth_token and oauth_token_secret for an AccessToken instance.



23
24
25
26
27
28
# File 'lib/allplayers/api.rb', line 23

def prepare_access_token(oauth_token, oauth_token_secret, consumer_token, consumer_secret)
  consumer = OAuth::Consumer.new(consumer_token, consumer_secret, {:site => @base_uri})
  # now create the access token object from passed values
  token_hash = {:oauth_token => oauth_token, :oauth_token_secret => oauth_token_secret}
  @access_token = OAuth::AccessToken.from_hash(consumer, token_hash)
end

#remove_headers(headers = {}) ⇒ Object

Remove headers from a session.



41
42
43
44
45
# File 'lib/allplayers/api.rb', line 41

def remove_headers(headers = {})
  headers.each do |header, value|
    @headers.delete(header)
  end
end