Class: Shelbytv::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/shelbytv/base.rb

Constant Summary collapse

API =
"http://api.shelby.tv/v2/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
14
15
16
17
# File 'lib/shelbytv/base.rb', line 9

def initialize(*args)
  if args.size == 2
    @consumer_key, @consumer_secret = args
  elsif args.size == 4
    @consumer_key, @consumer_secret, @auth_token, @auth_secret = args
  else
    raise ArgumentError, "You need to pass in the consumer tokens as well as the auth tokens"
  end
end

Instance Attribute Details

#auth_secretObject

Returns the value of attribute auth_secret.



7
8
9
# File 'lib/shelbytv/base.rb', line 7

def auth_secret
  @auth_secret
end

#auth_tokenObject

Returns the value of attribute auth_token.



7
8
9
# File 'lib/shelbytv/base.rb', line 7

def auth_token
  @auth_token
end

#request_tokenObject

Returns the value of attribute request_token.



7
8
9
# File 'lib/shelbytv/base.rb', line 7

def request_token
  @request_token
end

Instance Method Details

#access_token(oauth_verifier) ⇒ Object



46
47
48
# File 'lib/shelbytv/base.rb', line 46

def access_token(oauth_verifier)
  @request_token.get_access_token(:oauth_verifier => oauth_verifier)
end

#authorize_urlObject



40
41
42
43
44
# File 'lib/shelbytv/base.rb', line 40

def authorize_url
  consumer = OAuth::Consumer.new(@consumer_key, @consumer_secret, { :site=>"http://dev.shelby.tv" })
  @request_token = consumer.get_request_token
  @request_token.authorize_url
end

#channelsObject



19
20
21
# File 'lib/shelbytv/base.rb', line 19

def channels
  Shelbytv::ChannelProxy.new(self)
end

#get(path, params = {}) ⇒ Object



31
32
33
34
# File 'lib/shelbytv/base.rb', line 31

def get(path, params={})
  query = params.map { |k,v| "#{k}=#{v}" }.join("&")
  JSON.parse(client.get(API + path + "?" + OAuth::Helper.escape(query)).body)
end

#post(path, params = {}) ⇒ Object



36
37
38
# File 'lib/shelbytv/base.rb', line 36

def post(path, params={})
  JSON.parse(client.get(API + path, params))
end

#userObject



23
24
25
# File 'lib/shelbytv/base.rb', line 23

def user
  Shelbytv::User.new(self, get('users.json').first)
end

#usersObject



27
28
29
# File 'lib/shelbytv/base.rb', line 27

def users
  Shelbytv::UserProxy.new(self)
end