Module: Metwit

Defined in:
lib/metwit.rb,
lib/metwit/auth.rb,
lib/metwit/user.rb,
lib/metwit/metag.rb,
lib/metwit/version.rb,
lib/metwit/weather.rb,
lib/metwit/constants.rb

Overview

All classes are qualified in the namespace Metwit

Defined Under Namespace

Classes: AccessTokenExpiredError, Metag, User, Weather

Constant Summary collapse

VERSION =

The version of the metwit gem

"0.0.5"
BASE_URL =
"https://api.metwit.com/v2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.access_tokenObject

The access token



13
14
15
# File 'lib/metwit/auth.rb', line 13

def access_token
  @access_token
end

.client_idObject

The developer application id



7
8
9
# File 'lib/metwit/auth.rb', line 7

def client_id
  @client_id
end

.client_secretObject

The developer application secret



10
11
12
# File 'lib/metwit/auth.rb', line 10

def client_secret
  @client_secret
end

.refresh_tokenObject

The refresh token



16
17
18
# File 'lib/metwit/auth.rb', line 16

def refresh_token
  @refresh_token
end

Class Method Details

.get_access_tokenObject



35
36
37
38
39
40
41
42
43
# File 'lib/metwit/auth.rb', line 35

def get_access_token
  url = 'https://api.metwit.com/token/'
  response = HTTParty.post(url, :body => {:grant_type => 'client_credentials'},
                           :headers => {'Authorization' => "Basic #{Base64.strict_encode64(client_id+":"+client_secret)}"})
  # TODO: check if correctly logged
  @logged = true
  @refresh_token = response['refresh_token']
  @access_token = response['access_token']
end

.logged?Boolean

Tell if login was successuful

Returns:

  • (Boolean)


20
21
22
# File 'lib/metwit/auth.rb', line 20

def logged?
  @logged ||= false
end

.refresh_access_tokenObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/metwit/auth.rb', line 24

def refresh_access_token
  url = 'https://api.metwit.com/token/'
  response = HTTParty.post(url, :body => {:grant_type => 'refresh_token',
                           :refresh_token => refresh_token},
                           :headers => {'Authorization' => "Basic #{Base64.strict_encode64(client_id+":"+client_secret)}"})
  # TODO: check if correctly logged
  @logged = true
  @refresh_token = response['refresh_token'] if response['refresh_token']
  @access_token = response['access_token']
end