Class: Reach5::API

Inherits:
Object
  • Object
show all
Defined in:
lib/reach5/api.rb

Overview

Handles all calls to Reach5’s API.

Instance Method Summary collapse

Instance Method Details

#get_access_tokenObject

Get a new access token.

Example:

Reach5::API.new.get_access_token
# => {
#      "auth" => {
#        "accessToken" => "f00b4r",
#        "expires" => 43200
#      },
#      "status" => "success",
#    }


15
16
17
18
19
20
21
22
# File 'lib/reach5/api.rb', line 15

def get_access_token
  params = {
    client_key: Reach5.configuration.client_key,
    client_secret: Reach5.configuration.client_secret,
  }
  request = HTTP.get("#{host}/api/v1/access_token", params: params)
  request.parse
end

#get_profiles(page: 1, count: 10) ⇒ Object

List profiles

Example:

Reach5::API.new.get_profiles

# => {
#      "total" => 42,
#      "items" => […],
#      "status" => "success",
#    }


58
59
60
61
62
63
64
65
# File 'lib/reach5/api.rb', line 58

def get_profiles(page: 1, count: 10)
  params = {
    access_token: access_token,
    page: page,
    count: count,
  }
  HTTP.get("#{host}/api/v1/profile", params: params).parse
end

#post_login(provider:, provider_token:, provider_secret: nil, user_agent: nil) ⇒ Object

Collects and stores profile data from an Auth provider.

Example:

Reach5::API.new.(provider: 'facebook',
                           provider_token: 'f00b4r')
# => {
#      "profile" => {
#        …
#      },
#      "status" => "success",
#    }


35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/reach5/api.rb', line 35

def (provider:,
               provider_token:,
               provider_secret: nil,
               user_agent: nil)
  params = {
    provider: provider,
    provider_token: provider_token,
    provider_secret: provider_secret,
    user_agent: user_agent,
  }
  HTTP.post("#{host}/api/v1/login", params: params).parse
end