Class: UplandMobileCommonsRest::Client

Inherits:
Vertebrae::API
  • Object
show all
Defined in:
lib/upland_mobile_commons_rest/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
# File 'lib/upland_mobile_commons_rest/client.rb', line 7

def initialize(options = {}, &block)
  self.username = options[:username]
  self.password = options[:password]
  self.company_key = options[:company_key]
  super(options, &block)
end

Instance Attribute Details

#company_keyObject

Returns the value of attribute company_key.



5
6
7
# File 'lib/upland_mobile_commons_rest/client.rb', line 5

def company_key
  @company_key
end

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/upland_mobile_commons_rest/client.rb', line 5

def password
  @password
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/upland_mobile_commons_rest/client.rb', line 5

def username
  @username
end

Instance Method Details

#campaignsObject

Helper functions to let consumers do things like ‘client.campaigns.list`



52
53
54
# File 'lib/upland_mobile_commons_rest/client.rb', line 52

def campaigns
  @_campaigns ||= UplandMobileCommonsRest::Campaigns.new(client: self)
end

#default_optionsObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/upland_mobile_commons_rest/client.rb', line 14

def default_options
  {
    host: 'secure.mcommons.com',
    prefix: '/api',
    user_agent: 'ruby: UplandMobileCommonsRest',
    content_type: 'application/x-www-form-urlencoded',
    additional_headers: {
      'Accept' => 'application/xml'
    }
  }
end

#extract_data_from_params(params) ⇒ Object

:nodoc:



46
47
48
# File 'lib/upland_mobile_commons_rest/client.rb', line 46

def extract_data_from_params(params) # :nodoc:
  URI.encode_www_form(params)
end

#groupsObject



56
57
58
# File 'lib/upland_mobile_commons_rest/client.rb', line 56

def groups
  @_groups ||= UplandMobileCommonsRest::Groups.new(client: self)
end

#profilesObject



60
61
62
# File 'lib/upland_mobile_commons_rest/client.rb', line 60

def profiles
  @_profiles ||= UplandMobileCommonsRest::Profiles.new(client: self)
end

#setupObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/upland_mobile_commons_rest/client.rb', line 26

def setup
  connection.stack do |builder|
    # Request middlewares, in the order they should run
    builder.use Faraday::Request::Multipart
    builder.use Faraday::Request::UrlEncoded
    if connection.configuration.authenticated?
      builder.use Faraday::Request::BasicAuthentication, connection.configuration.username,
                  connection.configuration.password
    end

    # Response middlewares, in the *reverse* order they should run
    builder.use UplandMobileCommonsRest::TypedErrorMiddleware
    builder.use Faraday::Response::Logger if ENV['DEBUG']
    builder.use FaradayMiddleware::ParseXml
    builder.use UplandMobileCommonsRest::HttpErrorMiddleware

    builder.adapter connection.configuration.adapter
  end
end