Class: Frontapp::Client
- Inherits:
-
Object
- Object
- Frontapp::Client
- Includes:
- Channels, Comments, ContactGroups, Contacts, Conversations, Events, Inboxes, Messages, Rules, Tags, Teammates
- Defined in:
- lib/frontapp/client.rb,
lib/frontapp/client/tags.rb,
lib/frontapp/client/rules.rb,
lib/frontapp/client/events.rb,
lib/frontapp/client/inboxes.rb,
lib/frontapp/client/channels.rb,
lib/frontapp/client/comments.rb,
lib/frontapp/client/contacts.rb,
lib/frontapp/client/messages.rb,
lib/frontapp/client/teammates.rb,
lib/frontapp/client/conversations.rb,
lib/frontapp/client/contact_groups.rb
Defined Under Namespace
Modules: Channels, Comments, ContactGroups, Contacts, Conversations, Events, Inboxes, Messages, Rules, Tags, Teammates
Instance Method Summary collapse
- #create(path, body) ⇒ Object
- #create_without_response(path, body) ⇒ Object
- #delete(path, body = {}) ⇒ Object
- #get(path) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #list(path, params = {}) ⇒ Object
- #update(path, body) ⇒ Object
Methods included from Teammates
#get_teammate, #get_teammate_conversations, #get_teammate_inboxes, #teammates, #update_teammate!
Methods included from Tags
#create_tag!, #get_tag, #get_tag_conversations, #tags
Methods included from Rules
Methods included from Messages
#get_message, #import_message, #receive_custom_message, #send_message, #send_reply
Methods included from Inboxes
#create_inbox!, #get_inbox, #get_inbox_channels, #get_inbox_conversations, #get_inbox_teammates, #inboxes
Methods included from Events
Methods included from Conversations
#conversations, #get_conversation, #get_conversation_events, #get_conversation_followers, #get_conversation_inboxes, #get_conversation_messages, #update_conversation!
Methods included from Contacts
#add_contact_handle!, #add_contact_note!, #contacts, #create_contact!, #delete_contact!, #delete_contact_handle!, #get_contact, #get_contact_conversations, #get_contact_notes, #update_contact!
Methods included from ContactGroups
#add_contacts_to_contact_group!, #contact_groups, #create_contact_group!, #delete_contact_group!, #get_contact_group_contacts
Methods included from Comments
#create_comment!, #get_comment, #get_comment_mentions, #get_conversation_comments
Methods included from Channels
#channels, #create_channel!, #get_channel, #get_channel_inbox, #update_channel!
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
31 32 33 34 35 36 37 |
# File 'lib/frontapp/client.rb', line 31 def initialize(={}) auth_token = [:auth_token] @headers = HTTP.headers({ Accept: "application/json", Authorization: "Bearer #{auth_token}" }) end |
Instance Method Details
#create(path, body) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/frontapp/client.rb', line 63 def create(path, body) res = @headers.post("#{base_url}#{path}", json: body) response = JSON.parse(res.to_s) if !res.status.success? raise "Response: #{res.inspect}\n Body: #{res.body}\nRequest: #{body.to_json.inspect}" end response end |
#create_without_response(path, body) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/frontapp/client.rb', line 72 def create_without_response(path, body) res = @headers.post("#{base_url}#{path}", json: body) if !res.status.success? raise "Response: #{res.inspect}\n Body: #{res.body}\nRequest: #{body.to_json.inspect}" end end |
#delete(path, body = {}) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/frontapp/client.rb', line 86 def delete(path, body = {}) res = @headers.delete("#{base_url}#{path}", json: body) if !res.status.success? raise "Response: #{res.inspect}\n Body: #{res.body}\nRequest: #{body.to_json.inspect}" end end |
#get(path) ⇒ Object
58 59 60 61 |
# File 'lib/frontapp/client.rb', line 58 def get(path) res = @headers.get("#{base_url}#{path}") JSON.parse(res.to_s) end |
#list(path, params = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/frontapp/client.rb', line 39 def list(path, params = {}) items = [] last_page = false query = format_query(params) url = "#{base_url}#{path}?#{query}" until last_page res = @headers.get(url) response = JSON.parse(res.to_s) items.concat(response["_results"]) if response["_results"] pagination = response["_pagination"] if pagination.nil? || pagination["next"].nil? last_page = true else url = pagination["next"] end end items end |
#update(path, body) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/frontapp/client.rb', line 79 def update(path, body) res = @headers.patch("#{base_url}#{path}", json: body) if !res.status.success? raise "Response: #{res.inspect}\n Body: #{res.body}\nRequest: #{body.to_json.inspect}" end end |