class Chatmeter::API
Constants
- HEADERS
- OPTIONS
Public Class Methods
# 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
GET /accounts
# File lib/chatmeter/api/account.rb, line 14 def accounts(query={}) request( expects: 200, method: :get, path: '/accounts', query: query )[:accounts] end
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
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
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
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
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
# 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
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
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
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
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
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 /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 /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 /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 /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 /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 /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 /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
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'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
# 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 /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 /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 /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
# File lib/chatmeter/api/listings.rb, line 7 def get_listings(params={}) request( expects: 200, method: :get, path: "/listings", query: params ) end
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 /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 /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}
# File lib/chatmeter/api/user_management.rb, line 15 def get_user(user_id) request( expects: 200, method: :get, path: "/user/#{user_id}" ) end
# 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
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
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
GET /groups
# File lib/chatmeter/api/group.rb, line 5 def list_all_groups request( expects: 200, method: :get, path: "/groups" )[:groups] end
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
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
# 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
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
# 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
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
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
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
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
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
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
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
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
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
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
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