class NameDrop::Client

Public Class Methods

new(*) click to toggle source
# File lib/name_drop/client.rb, line 5
def initialize(*)
end

Public Instance Methods

alerts() click to toggle source
# File lib/name_drop/client.rb, line 8
def alerts
  Resources::BaseFactory.new(self, 'Alert')
end
delete(endpoint) click to toggle source
# File lib/name_drop/client.rb, line 32
def delete(endpoint)
  request(:delete, endpoint)
end
get(endpoint) click to toggle source
# File lib/name_drop/client.rb, line 20
def get(endpoint)
  request(:get, endpoint)
end
mentions() click to toggle source
# File lib/name_drop/client.rb, line 12
def mentions
  Resources::BaseFactory.new(self, 'Mention')
end
post(endpoint, attributes) click to toggle source
# File lib/name_drop/client.rb, line 24
def post(endpoint, attributes)
  request(:post, endpoint, attributes)
end
put(endpoint, attributes) click to toggle source
# File lib/name_drop/client.rb, line 28
def put(endpoint, attributes)
  request(:put, endpoint, attributes)
end
shares() click to toggle source
# File lib/name_drop/client.rb, line 16
def shares
  Resources::BaseFactory.new(self, 'Share')
end

Private Instance Methods

create_request_hash(method, endpoint, attributes) click to toggle source
# File lib/name_drop/client.rb, line 45
def create_request_hash(method, endpoint, attributes)
  request_hash = { method: method, url: request_url(endpoint), headers: headers }
  request_hash[:payload] = attributes.to_json unless attributes.empty?
  request_hash
end
error_message(method) click to toggle source
# File lib/name_drop/client.rb, line 51
def error_message(method)
  "Error #{error_verbs[method]} Mention Resource"
end
error_verbs() click to toggle source
# File lib/name_drop/client.rb, line 55
def error_verbs
  { get: 'retrieving', post: 'creating', put: 'updating', delete: 'deleting' }
end
headers() click to toggle source
# File lib/name_drop/client.rb, line 59
def headers
  @headers ||= { 'Content-Type' => 'application/json',
                 'Accept-Version' => '1.8',
                 'Authorization' => "Bearer #{NameDrop.configuration.access_token}" }
end
request(method, endpoint, attributes = {}) click to toggle source
# File lib/name_drop/client.rb, line 38
def request(method, endpoint, attributes = {})
  response = RestClient::Request.execute(create_request_hash(method, endpoint, attributes))
  JSON.parse(response) unless response.empty?
rescue RestClient::ExceptionWithResponse => err
  raise NameDrop::Error.new(error_message(method), JSON.parse(err.response))
end
request_url(endpoint) click to toggle source
# File lib/name_drop/client.rb, line 65
def request_url(endpoint)
  "https://web.mention.net/api/accounts/#{NameDrop.configuration.account_id}/#{endpoint}"
end