class Chatmeter::API

Constants

HEADERS
OPTIONS

Public Class Methods

new(options={}) click to toggle source
# File lib/chatmeter/api.rb, line 44
def initialize(options={})
  options = OPTIONS.merge(options)
  options = options.merge(headers: HEADERS)

  if !@api_key && options.has_key?(:username) && options.has_key?(:password)
    username = options.delete(:username)
    password = options.delete(:password)
    @connection = Excon.new("#{options[:scheme]}://#{options[:host]}", options)
    @api_key = self.post_login(username, password)[:token]
  end

  headers = HEADERS.merge({ Authorization: @api_key })
  @connection = Excon.new("#{options[:scheme]}://#{options[:host]}", headers: headers, mock: options[:mock])
end

Public Instance Methods

accounts(query={}) click to toggle source

GET /accounts

# File lib/chatmeter/api/account.rb, line 14
def accounts(query={})
  request(
    expects: 200,
    method:  :get,
    path:    '/accounts',
    query:    query
  )[:accounts]
end
add_group_to_user(user_id, params) click to toggle source

POST /users/{user_id}/groups

# File lib/chatmeter/api/user_group_access.rb, line 14
def add_group_to_user(user_id, params)
  request(
    expects:  200,
    method:   :post,
    path:     "/users/#{user_id}/groups",
    body:    params.to_json
  )
end
add_location_to_user(user_id, location_ids) click to toggle source

POST /users/{user_id}/locations

# File lib/chatmeter/api/user_location_access.rb, line 14
def add_location_to_user(user_id, location_ids)
  request(
    expects: 200,
    method: :post,
    path: "/users/#{user_id}/locations",
    body: {
      "locationIds": location_ids
    }.to_json
  )
end
add_new_account(params) click to toggle source

POST /accounts

# File lib/chatmeter/api/account.rb, line 24
def add_new_account(params)
  request(
    expects:  200,
    method:   :post,
    path:     "/accounts",
    body:     params.to_json
  )
end
add_new_location(fields) click to toggle source

POST /locations

# File lib/chatmeter/api/location.rb, line 24
def add_new_location(fields)
  request(
    expects: 200,
    method:  :post,
    path:    '/locations',
    body:    fields.to_json
  )
end
add_reviews(params) click to toggle source

POST /v5/reviews

# File lib/chatmeter/api/review.rb, line 54
def add_reviews(params)
  request(
    expects:  [200, 201],
    method:   :post,
    path:     "/reviews",
    body:     params.to_json
  )
end
add_sub_account(user_id, params) click to toggle source
# File lib/chatmeter/api/user_management.rb, line 72
def add_sub_account(user_id, params)
  request(
    expects: 200,
    method: :put,
    path: "/users/#{user_id}/accounts",
    body: params.to_json
  )
end
aggregate_reports(review_id, params={}) click to toggle source

GET /reviews/reports/{ReportId}

# File lib/chatmeter/api/review.rb, line 44
def aggregate_reports(review_id, params={})
  request(
    expects: 200,
    method:  :get,
    path:    "/reviews/reports/{report_id}",
    query:    params
  )
end
competitors(params) click to toggle source

GET /competitors

# File lib/chatmeter/api/competitors.rb, line 5
def competitors(params)
  request(
    expects: 200,
    method:  :post,
    path:    "/competitors",
    body:    params.to_json
  )
end
create_new_campaign(params) click to toggle source

POST /reviewBuilder/campaign/create

# File lib/chatmeter/api/campaign.rb, line 14
def create_new_campaign(params)
  request(
    expects:  201,
    method:   :post,
    path:     "/reviewBuilder/campaign/create",
    body:     params.to_json
  )
end
create_new_group(params) click to toggle source

POST /groups

# File lib/chatmeter/api/group.rb, line 14
def create_new_group(params)
  request(
    expects:  200,
    method:   :post,
    path:     "/groups",
    body:    params.to_json
  )
end
create_new_user(params) click to toggle source

POST /users

# File lib/chatmeter/api/user_management.rb, line 24
def create_new_user(params)
  request(
    expects:  200,
    method:   :post,
    path:     "/users",
    body:     params.to_json
  )
end
delete_campaign(campaign_id) click to toggle source

DELETE /reviewBuilder/campaign/delete/{campaignId}

# File lib/chatmeter/api/campaign.rb, line 52
def delete_campaign(campaign_id)
  request(
    expects:  200,
    method:   :delete,
    path:     "/reviewBuilder/campaign/delete/#{campaign_id}"
  )
end
delete_group(group_id) click to toggle source

DELETE /groups/{group_id}

# File lib/chatmeter/api/group.rb, line 34
def delete_group(group_id)
  request(
    expects:  200,
    method:   :delete,
    path:     "/groups/#{group_id}"
  )
end
delete_group_access(user_id, group_ids) click to toggle source

DELETE /users/{user_id}/groups?groupIds={group_ids}

# File lib/chatmeter/api/user_group_access.rb, line 24
def delete_group_access(user_id, group_ids)
  request(
    expects:  200,
    method:   :delete,
    path:     "/users/#{user_id}/groups?groupIds=#{group_ids.join(',')}"
  )
end
delete_group_locations(group_id,locationsIds) click to toggle source

DELETE /groups/{group_id}/locations

# File lib/chatmeter/api/group.rb, line 53
def delete_group_locations(group_id,locationsIds)
  request(
    expects:  200,
    method:   :delete,
    path:     "/groups/#{group_id}/locations?locationIds=#{locationsIds.join(',')}"
  )
end
delete_location(location_id) click to toggle source

DELETE /locations/{locationId}

# File lib/chatmeter/api/location.rb, line 44
def delete_location(location_id)
  request(
    expects:  200,
    method:   :delete,
    path:     "/locations/#{location_id}"
  )
end
delete_review(review_id, params) click to toggle source

DELETE /reviews/{review_id}

# File lib/chatmeter/api/review.rb, line 74
def delete_review(review_id, params)
  request(
    expects:  200,
    method:   :delete,
    path:     "/reviews/#{review_id}",
    query:    params
  )
end
delete_user(user_id) click to toggle source

DELETE /users/{user_id}

# File lib/chatmeter/api/user_management.rb, line 54
def delete_user(user_id)
  request(
    expects:  200,
    method:   :delete,
    path:     "/users/#{user_id}"
  )
end
enable_user(user_id, params) click to toggle source

POST /users

# File lib/chatmeter/api/user_management.rb, line 63
def enable_user(user_id, params)
  request(
    expects:  200,
    method:   :post,
    path:     "/users/#{user_id}/status",
    body:    params.to_json
  )
end
get_account_groups(account_id) click to toggle source

GET account's groups

# File lib/chatmeter/api/account.rb, line 34
def get_account_groups(account_id)
  request(
    expects: 200,
    method:  :get,
    path:    "/groups",
    query: {
      accountId: account_id
    }
  )[:groups]
end
get_accounts_for_user(user_id) click to toggle source

GET /accounts for user

# File lib/chatmeter/api/account.rb, line 5
def get_accounts_for_user(user_id)
  request(
    expects: 200,
    method:  :get,
    path:    "/accounts/forUser/#{user_id}"
  )[:accountIds]
end
get_all_locations(query={}) click to toggle source

GET /locations

# File lib/chatmeter/api/location.rb, line 5
def get_all_locations(query={})
  request(
    expects: 200,
    method:  :get,
    path:    '/locations',
    query:  query
  )
end
get_all_reviews(params={}) click to toggle source

GET /reviews

# File lib/chatmeter/api/review.rb, line 15
def get_all_reviews(params={})
  request(
    expects: 200,
    method:  :get,
    path:    "/reviews",
    query:    params
  )[:reviews]
end
get_campaign_by_id(campaign_id) click to toggle source

GET /reviewBuilder/campaign/get/{campaignId}

# File lib/chatmeter/api/campaign.rb, line 24
def get_campaign_by_id(campaign_id)
  request(
    expects:  200,
    method:   :get,
    path:     "/reviewBuilder/campaign/get/#{campaign_id}"
  )
end
get_listings(params={}) click to toggle source

GET /listings

# File lib/chatmeter/api/listings.rb, line 7
def get_listings(params={})
  request(
    expects: 200,
    method:  :get,
    path:    "/listings",
    query:   params
  )
end
get_locations_by_reseller_location_id(reseller_location_id) click to toggle source

GET /locations/externalId/{resellerLocationId}

# File lib/chatmeter/api/location.rb, line 15
def get_locations_by_reseller_location_id(reseller_location_id)
  request(
    expects: 200,
    method:  :get,
    path:    "/locations/externalId/#{reseller_location_id}"
  )
end
get_review_metrics(params={}) click to toggle source

GET /dashboard/reviewReport

# File lib/chatmeter/api/review.rb, line 5
def get_review_metrics(params={})
  request(
    expects: 200,
    method:  :get,
    path:    "/dashboard/reviewReport",
    query:    params
  )
end
get_single_review(review_id) click to toggle source

GET /reviews/{reviewId}

# File lib/chatmeter/api/review.rb, line 25
def get_single_review(review_id)
  request(
    expects: 200,
    method:  :get,
    path:    "/reviews/#{review_id}"
  )
end
get_user(user_id) click to toggle source

GET /user/{user_id}

# File lib/chatmeter/api/user_management.rb, line 15
def get_user(user_id)
  request(
    expects: 200,
    method:  :get,
    path:    "/user/#{user_id}"
  )
end
get_user_locations(user_id) click to toggle source
# File lib/chatmeter/api/user_management.rb, line 81
def get_user_locations(user_id)
  request(
    expects: 200,
    method: :get,
    path: "/users/#{user_id}/locations"
  )
end
groups_for_user(user_id) click to toggle source

GET /users/{user_id}/groups

# File lib/chatmeter/api/user_group_access.rb, line 5
def groups_for_user(user_id)
  request(
    expects: 200,
    method:  :get,
    path:    "/users/#{user_id}/groups"
  )
end
list_all_campaigns() click to toggle source

GET /reviewBuilder/campaign/get

# File lib/chatmeter/api/campaign.rb, line 5
def list_all_campaigns
  request(
    expects: 200,
    method:  :get,
    path:    "/reviewBuilder/campaign/get"
  )
end
list_all_groups() click to toggle source

GET /groups

# File lib/chatmeter/api/group.rb, line 5
def list_all_groups
  request(
    expects: 200,
    method:  :get,
    path:    "/groups"
  )[:groups]
end
list_all_users(params={}) click to toggle source

GET /users

# File lib/chatmeter/api/user_management.rb, line 5
def list_all_users(params={})
  request(
    expects: 200,
    method:  :get,
    path:    "/users",
    query:    params
  )[:users]
end
locations_for_user(user_id) click to toggle source

GET /users/{user_id}/locations

# File lib/chatmeter/api/user_location_access.rb, line 5
def locations_for_user(user_id)
  request(
    expects: 200,
    method:  :get,
    path:    "/users/#{user_id}/locations"
  )
end
post_login(username, password) click to toggle source
# File lib/chatmeter/api/login.rb, line 4
def post_login(username, password)
  request(
    expects: 200,
    method:  :post,
    path:    '/login',
    body:    { username: username, password: password }.to_json
  )
end
remove_location_access(user_id, params) click to toggle source

DELETE /users/{user_id}/locations?locationIds={location_ids}

# File lib/chatmeter/api/user_location_access.rb, line 26
def remove_location_access(user_id, params)
  request(
    expects:  200,
    method:   :post,
    path:     "/users/#{user_id}/locations/delete",
    body: params.to_json
  )
end
request(params, &block) click to toggle source
# File lib/chatmeter/api.rb, line 59
def request(params, &block)
  params[:path] = "/#{OPTIONS[:api_version]}#{params[:path]}"

  begin
    response = @connection.request(params, &block)
  rescue Excon::Errors::HTTPStatusError => error
    klass = case error.response.status
    when 400 then Chatmeter::API::Errors::BadRequest
    when 401 then Chatmeter::API::Errors::Unauthorized
    when 403 then Chatmeter::API::Errors::Forbidden
    when 404 then Chatmeter::API::Errors::NotFound
    when /50./ then Chatmeter::API::Errors::RequestFailed
    else Chatmeter::API::Errors::ErrorWithResponse
    end

    reerror = klass.new(error.message, error.response)
    reerror.set_backtrace(error.backtrace)
    raise(reerror)
  end

  if response.body && !response.body.empty?
    begin
      response.body = MultiJson.load(response.body, symbolize_keys: true)
    rescue
      if response.headers['Content-Type'] === 'application/json'
        raise
      end
      # leave non-JSON body as is
    end
  end

  @connection.reset
  response.body || ""
end
respond_to_review(review_id, params) click to toggle source

POST /reviews/{ReviewId}/responses

# File lib/chatmeter/api/review.rb, line 34
def respond_to_review(review_id, params)
  request(
    expects:  200,
    method:   :post,
    path:     "/reviews/#{review_id}/responses",
    body:     params.to_json
  )
end
restore_location(location_ids) click to toggle source

PUT /locations/restore (array)

# File lib/chatmeter/api/location.rb, line 53
def restore_location(location_ids)
  request(
    expects: 200,
    method:  :put,
    path:    '/locations/restore',
    body:    location_ids.to_json
  )
end
review_not_mine(review_id, params) click to toggle source

POST /reviews/{reviewId}/notMine

# File lib/chatmeter/api/review.rb, line 64
def review_not_mine(review_id, params)
  request(
    expects:  200,
    method:   :post,
    path:     "/reviews/#{review_id}/notMine",
    body:     params.to_json
  )
end
search_campaign(params={}) click to toggle source

GET /reviewBuilder/campaign

# File lib/chatmeter/api/campaign.rb, line 43
def search_campaign(params={})
  request(
    expects:  200,
    method:   :get,
    path:     "/reviewBuilder/campaign?#{params.to_query}"
  )
end
sso_token_for(user_name) click to toggle source

GET /singlesignon/generateLoginToken?username={username}

# File lib/chatmeter/api/single_signon.rb, line 5
def sso_token_for(user_name)
  request(
    expects: 200,
    method:  :get,
    path:    "/singlesignon/generateLoginToken?username=#{user_name}"
  )[:ssoToken]
end
update_campaign(campaign_id, params) click to toggle source

PUT /reviewBuilder/campaign/{campaignId}

# File lib/chatmeter/api/campaign.rb, line 33
def update_campaign(campaign_id, params)
  request(
    expects:  200,
    method:   :put,
    path:     "/reviewBuilder/campaign/#{campaign_id}",
    body:     params.to_json
  )
end
update_group(group_id, params) click to toggle source

PUT /groups/{group_id}

# File lib/chatmeter/api/group.rb, line 24
def update_group(group_id, params)
  request(
    expects:  200,
    method:   :put,
    path:     "/groups/#{group_id}",
    body:     params.to_json
  )
end
update_group_locations(group_id, params) click to toggle source

POST /groups/{group_id}/locations

# File lib/chatmeter/api/group.rb, line 43
def update_group_locations(group_id, params)
  request(
    expects:  200,
    method:   :post,
    path:     "/groups/#{group_id}/locations",
    body:     params.to_json
  )
end
update_location(location_id, fields) click to toggle source

PUT /locations/{locationId}

# File lib/chatmeter/api/location.rb, line 34
def update_location(location_id, fields)
  request(
    expects: 200,
    method:  :put,
    path:    "/locations/#{location_id}",
    body:    fields.to_json
  )
end
update_user(user_id, params) click to toggle source

PUT /users/{user_id}

# File lib/chatmeter/api/user_management.rb, line 34
def update_user(user_id, params)
  request(
    expects:  200,
    method:   :put,
    path:     "/users/#{user_id}",
    body:     params.to_json
  )
end
update_user_password(user_id, params) click to toggle source

PUT /users/{user_id}/password

# File lib/chatmeter/api/user_management.rb, line 44
def update_user_password(user_id, params)
  request(
    expects:  200,
    method:   :put,
    path:     "/users/#{user_id}/password",
    body:    params.to_json
  )
end