Class: Frontapp::Client
- Inherits:
-
Object
- Object
- Frontapp::Client
- Includes:
- Channels, Comments, ContactGroups, Contacts, Conversations, Events, Exports, Inboxes, Messages, Rules, Tags, Teammates, Teams, Topics
- Defined in:
- lib/frontapp/client.rb,
lib/frontapp/client/tags.rb,
lib/frontapp/client/rules.rb,
lib/frontapp/client/teams.rb,
lib/frontapp/client/events.rb,
lib/frontapp/client/topics.rb,
lib/frontapp/client/exports.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, Exports, Inboxes, Messages, Rules, Tags, Teammates, Teams, Topics
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 Exports
#create_export!, #create_export_for_team!, #exports, #get_export
Methods included from Topics
Methods included from Teams
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
39 40 41 42 43 44 45 46 47 |
# File 'lib/frontapp/client.rb', line 39 def initialize(={}) auth_token = [:auth_token] user_agent = [:user_agent] || "Frontapp Ruby Gem #{VERSION}" @headers = HTTP.headers({ Accept: "application/json", Authorization: "Bearer #{auth_token}", "User-Agent": user_agent }) end |
Instance Method Details
#create(path, body) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/frontapp/client.rb', line 79 def create(path, body) res = @headers.post("#{base_url}#{path}", json: body) response = JSON.parse(res.to_s) if !res.status.success? raise Error.from_response(res) end response end |
#create_without_response(path, body) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/frontapp/client.rb', line 88 def create_without_response(path, body) res = @headers.post("#{base_url}#{path}", json: body) if !res.status.success? raise Error.from_response(res) end end |
#delete(path, body = {}) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/frontapp/client.rb', line 102 def delete(path, body = {}) res = @headers.delete("#{base_url}#{path}", json: body) if !res.status.success? raise Error.from_response(res) end end |
#get(path) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/frontapp/client.rb', line 71 def get(path) res = @headers.get("#{base_url}#{path}") if !res.status.success? raise Error.from_response(res) end JSON.parse(res.to_s) end |
#list(path, params = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/frontapp/client.rb', line 49 def list(path, params = {}) items = [] last_page = false query = format_query(params) url = "#{base_url}#{path}?#{query}" until last_page res = @headers.get(url) if !res.status.success? raise Error.from_response(res) end 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
95 96 97 98 99 100 |
# File 'lib/frontapp/client.rb', line 95 def update(path, body) res = @headers.patch("#{base_url}#{path}", json: body) if !res.status.success? raise Error.from_response(res) end end |