Module: Picturelife

Defined in:
lib/picturelife.rb,
lib/picturelife/api.rb,
lib/picturelife/base.rb,
lib/picturelife/stub.rb,
lib/picturelife/util.rb,
lib/picturelife/error.rb,
lib/picturelife/oauth.rb,
lib/picturelife/ruler.rb

Defined Under Namespace

Modules: Ruler, Util Classes: Api, ApiError, NotAuthenticatedError, NotConfiguredError, OAuthError, RulerError, Stub

Constant Summary collapse

VERSION =
"0.0.2"
API_ENDPOINT =
"https://api.picturelife.com/"
OAUTH_ENDPOINT =
"https://api.picturelife.com/oauth/"
RULER_ENDPOINT =
"https://services.picturelife.com/ruler/"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.access_tokenObject

Returns the value of attribute access_token.



5
6
7
# File 'lib/picturelife/base.rb', line 5

def access_token
  @access_token
end

.client_idObject

Returns the value of attribute client_id.



3
4
5
# File 'lib/picturelife/base.rb', line 3

def client_id
  @client_id
end

.client_secretObject

Returns the value of attribute client_secret.



4
5
6
# File 'lib/picturelife/base.rb', line 4

def client_secret
  @client_secret
end

.redirect_uriObject

Returns the value of attribute redirect_uri.



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

def redirect_uri
  @redirect_uri
end

.refresh_tokenObject

Returns the value of attribute refresh_token.



6
7
8
# File 'lib/picturelife/base.rb', line 6

def refresh_token
  @refresh_token
end

.token_expiresObject (readonly)

Returns the value of attribute token_expires.



8
9
10
# File 'lib/picturelife/base.rb', line 8

def token_expires
  @token_expires
end

.user_idObject (readonly)

Returns the value of attribute user_id.



9
10
11
# File 'lib/picturelife/base.rb', line 9

def user_id
  @user_id
end

Class Method Details

.access_token_from_code=(code) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/picturelife/oauth.rb', line 19

def access_token_from_code=(code)
  needs_configuration!

  uri = [
    OAUTH_ENDPOINT,
    "access_token?",
    "client_id=#{@client_id}",
    "&client_secret=#{@client_secret}",
    "&code=#{code}",
    "&client_uuid=#{client_uuid}"
  ].join

  res = api_oauth_get(uri)

  if res['status'] != 200
    raise OAuthError.new(res['status'], res['error'], res)
  else
    @refresh_token = res['refresh_token']
    @user_id       = res['user_id']
    @token_expires = Time.at(res['expires'])
    @access_token  = res['access_token']        
  end
end

.authenticated?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/picturelife/base.rb', line 21

def authenticated?
  !! @access_token
end

.authorization_uriObject



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/picturelife/oauth.rb', line 6

def authorization_uri
  needs_configuration!

  [
    OAUTH_ENDPOINT,
    "authorize?",
    "client_id=#{@client_id}",
    "&client_secret=#{@client_secret}",
    "&redirect_uri=#{@redirect_uri}",
    "&response_type=code"
  ].join
end

.configured?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/picturelife/base.rb', line 15

def configured?
  @client_id     &&
  @client_secret &&
  @redirect_uri
end

.const_missing(name) ⇒ Object



3
4
5
# File 'lib/picturelife/stub.rb', line 3

def self.const_missing(name)
  Stub.new(underscore(name.to_s))
end

.reset_authentication!Object



32
33
34
35
36
37
# File 'lib/picturelife/base.rb', line 32

def reset_authentication!
  @access_token  = nil
  @refresh_token = nil
  @token_expires = nil
  @user_id       = nil
end

.reset_configuration!Object



25
26
27
28
29
30
# File 'lib/picturelife/base.rb', line 25

def reset_configuration!
  @client_id     = nil
  @client_secret = nil
  @redirect_uri  = nil
  reset_authentication!
end