Module: SocialPilot

Defined in:
lib/social_pilot.rb,
lib/social_pilot/account.rb,
lib/social_pilot/version.rb

Defined Under Namespace

Classes: Account, AuthenticationError, ConfigurationError, SocialPilotError

Constant Summary collapse

API_BASE =
"https://panel.socialpilot.co/oauth/"
VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.access_token=(value) ⇒ Object (writeonly)

Sets the attribute access_token

Parameters:

  • value

    the value to set the attribute access_token to.



17
18
19
# File 'lib/social_pilot.rb', line 17

def access_token=(value)
  @access_token = value
end

Class Method Details

.request(method, resource, params = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/social_pilot.rb', line 19

def request method, resource, params={}
    vd_access_token = params[:access_token] || SocialPilot.access_token

    params.merge!({access_token: vd_access_token})

    defined? vd_access_token or raise(
        ConfigurationError, "SocialPilot access token not configured"
    )
    defined? method or raise(
        ArgumentError, "Request method has not been specified"
    )
    defined? resource or raise(
        ArgumentError, "Request resource has not been specified"
    )

    if method == :get 
        headers = { :accept => :json, content_type: :json }.merge({params: params})
        payload = nil
    else
        headers = { :accept => :json, content_type: :json }
        payload = params
    end

    RestClient::Request.new({
        method: method,
        url: API_BASE + resource,
        payload: payload ? payload.to_json : nil,
        headers: headers
    }).execute do |response, request, result|
        str_response = response.to_str        
        str_response.blank? ? '' : JSON.parse(str_response)
    end
end