Class: Imgurz::Token

Inherits:
Struct
  • Object
show all
Defined in:
lib/imgurz/token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id

Returns:

  • (Object)

    the current value of client_id



8
9
10
# File 'lib/imgurz/token.rb', line 8

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret

Returns:

  • (Object)

    the current value of client_secret



8
9
10
# File 'lib/imgurz/token.rb', line 8

def client_secret
  @client_secret
end

Instance Method Details

#refresh(refresh_token) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/imgurz/token.rb', line 10

def refresh(refresh_token)
  uri = URI.parse Imgurz::TOKEN_ENDPOINT
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  request = Net::HTTP::Post.new uri.path
  request.set_form_data({
    refresh_token: refresh_token,
    client_id: client_id,
    client_secret: client_secret,
    grant_type: 'refresh_token'
  })
  response = http.request(request)
  JSON.parse response.body
end