Class: Videojuicer::Session

Inherits:
Object show all
Includes:
Configurable, OAuth::ProxyFactory
Defined in:
lib/videojuicer/session.rb

Instance Attribute Summary

Attributes included from Configurable

#local_config

Instance Method Summary collapse

Methods included from OAuth::ProxyFactory

#proxy_for

Methods included from Configurable

#api_version, #config, #configure!, #consumer_key, #consumer_secret, #host, #port, #protocol, #scope, #seed_name, #token, #token_secret, #user_id

Constructor Details

#initialize(options = {}) ⇒ Session

Returns a new instance of Session.



13
14
15
# File 'lib/videojuicer/session.rb', line 13

def initialize(options={})
  configure!(options)
end

Instance Method Details

#authorize!Object



68
69
70
71
# File 'lib/videojuicer/session.rb', line 68

def authorize!
  # GET tokens.json with magic params
  puts "not yet authorized"
end

#authorize_url(token = get_request_token) ⇒ Object

Generates and returns a fully-qualified signed URL that the user should be directed to by the consumer.

See oauth.net/core/1.0/#auth_step2 for details.

Can optionally be given a Mash previously obtained from a call to get_request_token, but in most cases this is not necessary - a request token will be requested and used automatically if one is not supplied.



46
47
48
# File 'lib/videojuicer/session.rb', line 46

def authorize_url(token=get_request_token)
  proxy_for(config.merge(:token=>token["oauth_token"], :token_secret=>token["oauth_token_secret"])).signed_url(:get, "/oauth/tokens/new", :oauth_callback=>token["oauth_callback"])
end

#exchange_request_token(token = get_request_token) ⇒ Object

Once a user has completed the OAuth authorisation procedure at the provider end, you may call exchange_request_token to make a request to the provider that will exchange your unauthorised request token for the corresponding authorised access token.

See oauth.net/core/1.0/#auth_step3 for details.

Returns a Mash that responds to the following methods: oauth_token - The token key to be used as the oauth_token in calls using this token. oauth_token_secret - The token secret to be used when signing requests using this token. expires - The date and time at which the token will become invalid. permissions - The permissions that you wish the token to have. Will be one of FooAttributeRegistry, write-user, read-master or write-master.



61
62
63
64
65
66
# File 'lib/videojuicer/session.rb', line 61

def exchange_request_token(token=get_request_token)
  proxy = proxy_for(config.merge(:token=>token["oauth_token"], :token_secret=>token["oauth_token_secret"]))
  response = proxy.get("/oauth/tokens.json")
  t = response.body
  Mash.new JSON.parse(t)["access_token"] rescue raise(JSON::ParserError, "could not parse: \n\n #{t}")
end

#get_request_tokenObject

Makes a call to the Videojuicer OAuth provider, requesting an unauthorised Request Token which will be returned as a Mash.

See oauth.net/core/1.0/#auth_step1 for details.

Each session will make only one request for an unauthorised request token. Further calls to get_request_token will return the same token and token secret.

The Mash responds to the following methods: oauth_token - The token key to be used as the oauth_token in calls using this token. oauth_token_secret - The token secret to be used when signing requests using this token. expires - The date and time at which the token will become invalid. permissions - The permissions that you wish the token to have. Will be one of FooAttributeRegistry, write-user, read-master or write-master.



30
31
32
33
34
35
36
# File 'lib/videojuicer/session.rb', line 30

def get_request_token
  # GET tokens.json
  response = proxy_for(config).get("/oauth/tokens.json")
  body = response.body
  @request_token_response ||= JSON.parse(body)
  @request_token_response["request_token"]
end