Class: Impermium::Client

Inherits:
Object
  • Object
show all
Includes:
Configuration, Content, User
Defined in:
lib/impermium/client.rb

Constant Summary

Constants included from Profile

Profile::REPORTER_USER_TYPE_VALUES

Constants included from Account

Account::REPORTER_USER_TYPE_VALUES

Constants included from Listing

Listing::REPORTER_USER_TYPE_VALUES

Constants included from Connection

Impermium::Connection::CONNECTION_TYPE_VALUES, Impermium::Connection::OPERATION_VALUES, Impermium::Connection::REPORTER_USER_TYPE_VALUES

Constants included from Comment

Impermium::Comment::REPORTER_USER_TYPE_VALUES

Constants included from Bookmark

Bookmark::REPORTER_USER_TYPE_VALUES

Constants included from BlogPost

BlogPost::REPORTER_USER_TYPE_VALUES

Constants included from Configuration

Impermium::Configuration::DEFAULT_ADAPTER, Impermium::Configuration::DEFAULT_API_KEY, Impermium::Configuration::DEFAULT_API_VERSION, Impermium::Configuration::DEFAULT_CLIENT_ID, Impermium::Configuration::DEFAULT_CLIENT_NAME, Impermium::Configuration::DEFAULT_ENDPOINT, Impermium::Configuration::VALID_CONFIG_KEYS

Instance Method Summary collapse

Methods included from Profile

#profile, #profile_analyst_feedback, #profile_user_feedback

Methods included from Account

#account, #account_analyst_feedback, #account_attempt, #account_login, #account_user_feedback

Methods included from Listing

#listing, #listing_analyst_feedback, #listing_user_feedback

Methods included from Connection

#connection, #connection_analyst_feedback, #connection_user_feedback

Methods included from Comment

#comment, #comment_analyst_feedback, #comment_user_feedback

Methods included from Bookmark

#bookmark, #bookmark_analyst_feedback, #bookmark_like, #bookmark_user_feedback

Methods included from BlogPost

#blog_post, #blog_post_analyst_feedback, #blog_post_user_feedback

Methods included from Configuration

#configure, extended, #options, #reset

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



16
17
18
19
20
21
# File 'lib/impermium/client.rb', line 16

def initialize(options = {})
  options = Impermium.options.merge(options)
  Configuration::VALID_CONFIG_KEYS.each do |key|
    send("#{key}=", options[key])
  end
end

Instance Method Details

#api_connectionObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/impermium/client.rb', line 23

def api_connection
  @api_connection ||= Faraday.new(:url => endpoint, :headers => default_headers) do |builder|
    builder.use Faraday::Response::Mashify
    builder.use Faraday::Response::ParseJson
    builder.use Faraday::Response::Raise4xx
    builder.request :json

    builder.adapter adapter
  end
end

#api_url(request_path) ⇒ Object



43
44
45
46
47
48
# File 'lib/impermium/client.rb', line 43

def api_url(request_path)
  url = URI.join(endpoint,
    request_path[-1] == '/' ? request_path  : request_path + "/",
    api_version + "/",
    api_key + "/").to_s
end

#post(url, options = {}) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/impermium/client.rb', line 34

def post(url, options={})
  api_connection.post do |req|
    req.url api_url(url)
    req.body = options
    req.headers['Content-Type'] = 'application/json'
    yield req if block_given?
  end.body
end