reamaze_api 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +21 -0
- data/README.md +54 -0
- data/lib/reamaze_api/article.rb +2 -1
- data/lib/reamaze_api/channel.rb +1 -1
- data/lib/reamaze_api/client.rb +47 -8
- data/lib/reamaze_api/contact.rb +1 -1
- data/lib/reamaze_api/conversation.rb +1 -1
- data/lib/reamaze_api/message.rb +2 -1
- data/lib/reamaze_api/resource.rb +1 -1
- data/lib/reamaze_api/version.rb +1 -1
- data/reamaze_api.gemspec +1 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fad68d5cd62a6332ad24030733db0643e2307ceb
|
4
|
+
data.tar.gz: eb3694f56e5124e5d364fc9e9b36ef08b4b1a3e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71a5d2f92737fcfbcfb9ebb6921f2ced6952c033527c0316420e377e2effab29a71ab7154d0bc86a15fe3c80e61807aab7573c7127e71d11b5ec29f4c53526f2
|
7
|
+
data.tar.gz: 617e7775821955deb3cc6b87c6fa722820032912ec296d3feb3b89e1974b922911824a61c84bd9197bfb176d4d4b1a11aec2e553f88ec7b243784b89663c42cd
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2016 Joshua Priddle <jpriddle@me.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person ob-
|
4
|
+
taining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without restric-
|
6
|
+
tion, including without limitation the rights to use, copy, modi-
|
7
|
+
fy, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
the Software, and to permit persons to whom the Software is fur-
|
9
|
+
nished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
16
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONIN-
|
17
|
+
FRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
19
|
+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -66,6 +66,37 @@ client.messages.all
|
|
66
66
|
client.messages.create
|
67
67
|
```
|
68
68
|
|
69
|
+
## Pagination
|
70
|
+
|
71
|
+
Reamaze paginates responses that return multiple resources (ie: this library's
|
72
|
+
`#all` methods), and by default you receive page 1. You can control which page
|
73
|
+
to fetch by passing the `:page` parameter:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
page1 = client.messages.all
|
77
|
+
page2 = client.messages.all(page: 2)
|
78
|
+
page3 = client.messages.all(page: 3)
|
79
|
+
```
|
80
|
+
|
81
|
+
## Auto-Pagination
|
82
|
+
|
83
|
+
Auto-pagination allows you to fetch _all_ results without having to manually
|
84
|
+
fetch each page. For example, with 3 pages of 30 conversations the following
|
85
|
+
would fetch all 90:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
conversations = client.conversations.all(auto_paginate: true)
|
89
|
+
```
|
90
|
+
|
91
|
+
**Beware of API rate limiting!** If you attempt to auto-paginate with a large
|
92
|
+
number of pages you may be rate limited by Reamaze. Make sure to apply filters
|
93
|
+
where necessary (eg: `all(auto_paginate: true, for: "me@example.com")`).
|
94
|
+
|
95
|
+
**Errors** If fetching any page is not successful the error will be returned
|
96
|
+
and no further pages will be fetched.
|
97
|
+
|
98
|
+
## Customization and Middleware
|
99
|
+
|
69
100
|
ReamazeAPI uses the [Faraday][] library for HTTP interactions, and by default,
|
70
101
|
Net::HTTP. To configure a different HTTP adapter you can set
|
71
102
|
`Faraday.default_adapter`:
|
@@ -141,3 +172,26 @@ push git commits and tags, and push the `.gem` file to
|
|
141
172
|
Bug reports and pull requests are welcome on GitHub at
|
142
173
|
https://github.com/itspriddle/reamaze_api.
|
143
174
|
|
175
|
+
## License
|
176
|
+
|
177
|
+
Released under the MIT license:
|
178
|
+
|
179
|
+
Copyright (c) 2016 Joshua Priddle <jpriddle@me.com>
|
180
|
+
|
181
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
182
|
+
of this software and associated documentation files (the "Software"), to deal
|
183
|
+
in the Software without restriction, including without limitation the rights
|
184
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
185
|
+
copies of the Software, and to permit persons to whom the Software is
|
186
|
+
furnished to do so, subject to the following conditions:
|
187
|
+
|
188
|
+
The above copyright notice and this permission notice shall be included in all
|
189
|
+
copies or substantial portions of the Software.
|
190
|
+
|
191
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
192
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
193
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
194
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
195
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
196
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
197
|
+
SOFTWARE.
|
data/lib/reamaze_api/article.rb
CHANGED
@@ -14,8 +14,9 @@ module ReamazeAPI
|
|
14
14
|
# Returns a Hash.
|
15
15
|
def all(params = {})
|
16
16
|
params = Utils.symbolize_hash(params)
|
17
|
+
url = articles_path(params.delete(:topic))
|
17
18
|
|
18
|
-
|
19
|
+
paginate url, :articles, params
|
19
20
|
end
|
20
21
|
|
21
22
|
# Public: Retrieves a specific KB article.
|
data/lib/reamaze_api/channel.rb
CHANGED
data/lib/reamaze_api/client.rb
CHANGED
@@ -37,9 +37,9 @@ module ReamazeAPI
|
|
37
37
|
|
38
38
|
# Public: Initialize a new Client instance.
|
39
39
|
#
|
40
|
-
# brand
|
41
|
-
# login
|
42
|
-
# token
|
40
|
+
# brand - Brand name (subdomain from your Reamaze URL)
|
41
|
+
# login - Reamaze login
|
42
|
+
# token - Reamaze API token
|
43
43
|
#
|
44
44
|
# Yields a Faraday::Connection if a block is given.
|
45
45
|
#
|
@@ -98,9 +98,9 @@ module ReamazeAPI
|
|
98
98
|
|
99
99
|
# Private: Submits an HTTP request to the upstream API.
|
100
100
|
#
|
101
|
-
# method
|
102
|
-
# path
|
103
|
-
# params
|
101
|
+
# method - HTTP method (eg: :get, :post)
|
102
|
+
# path - API path (without `/api/v1` prefix, eg: "/messages")
|
103
|
+
# params - Hash of parameters to send with the request (default: {})
|
104
104
|
#
|
105
105
|
# Raises a ReamazeAPI::Error for any HTTP response code 400-599 unless
|
106
106
|
# `ReamazeAPI.config.exceptions` is false.
|
@@ -118,11 +118,50 @@ module ReamazeAPI
|
|
118
118
|
Utils.error_hash(e)
|
119
119
|
end
|
120
120
|
|
121
|
+
# Private: Performs a GET request on the given path/resource. If results
|
122
|
+
# are more than one page, each additional page is fetched and added to the
|
123
|
+
# payload. If any page returns an error response, that response is
|
124
|
+
# immediately returned and no further requests are performed.
|
125
|
+
#
|
126
|
+
# NOTE: Beware of API rate limiting when using this method with large
|
127
|
+
# datasets.
|
128
|
+
#
|
129
|
+
# path - API path (without `/api/v1` prefix, eg: "/messages")
|
130
|
+
# resource - ReamazeAPI resource name (eg: `:messages`)
|
131
|
+
# params - Hash of parameters to send with the request (default: {})
|
132
|
+
#
|
133
|
+
# Returns a Hash.
|
134
|
+
def paginate(path, resource, params = {})
|
135
|
+
params = Utils.symbolize_hash(params)
|
136
|
+
auto_paginate = params.delete(:auto_paginate)
|
137
|
+
output = get(path, params)
|
138
|
+
page = params.fetch(:page, 1)
|
139
|
+
success = output[:success]
|
140
|
+
payload = output[:payload]
|
141
|
+
page_count = payload[:page_count]
|
142
|
+
|
143
|
+
if success && auto_paginate && page_count && page_count > page
|
144
|
+
more = paginate(path, resource, params.merge(
|
145
|
+
page: page.next,
|
146
|
+
auto_paginate: true
|
147
|
+
))
|
148
|
+
|
149
|
+
if more[:success] && more[:payload]
|
150
|
+
payload[resource].concat more[:payload][resource]
|
151
|
+
else
|
152
|
+
output[:success] = false
|
153
|
+
output[:payload] = more[:payload]
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
output
|
158
|
+
end
|
159
|
+
|
121
160
|
# Private: `get`, `put`, and `post` helper methods. These submit an HTTP
|
122
161
|
# request to the upstream API.
|
123
162
|
#
|
124
|
-
# path
|
125
|
-
# params
|
163
|
+
# path - API path (without `/api/v1` prefix, eg: "/messages")
|
164
|
+
# params - Hash of parameters to send with the request (default: {})
|
126
165
|
#
|
127
166
|
# Returns a Hash.
|
128
167
|
HTTP_METHODS.each do |method|
|
data/lib/reamaze_api/contact.rb
CHANGED
data/lib/reamaze_api/message.rb
CHANGED
@@ -16,8 +16,9 @@ module ReamazeAPI
|
|
16
16
|
# Returns a Hash.
|
17
17
|
def all(params = {})
|
18
18
|
params = Utils.symbolize_hash(params)
|
19
|
+
url = message_path(params.delete(:conversation_slug))
|
19
20
|
|
20
|
-
|
21
|
+
paginate url, :messages, params
|
21
22
|
end
|
22
23
|
|
23
24
|
# Public: Create a new message under the given conversation.
|
data/lib/reamaze_api/resource.rb
CHANGED
@@ -5,7 +5,7 @@ module ReamazeAPI
|
|
5
5
|
extend Forwardable
|
6
6
|
|
7
7
|
# Delegate HTTP actions back to the given Client.
|
8
|
-
def_delegators :@client, *Client::HTTP_METHODS
|
8
|
+
def_delegators :@client, :paginate, *Client::HTTP_METHODS
|
9
9
|
|
10
10
|
# Public: Initialize a new Resource instance. API resources should inherit
|
11
11
|
# from this class.
|
data/lib/reamaze_api/version.rb
CHANGED
data/reamaze_api.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reamaze_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Priddle
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- ".gitignore"
|
105
105
|
- ".travis.yml"
|
106
106
|
- Gemfile
|
107
|
+
- LICENSE
|
107
108
|
- README.md
|
108
109
|
- Rakefile
|
109
110
|
- bin/console
|
@@ -122,7 +123,8 @@ files:
|
|
122
123
|
- lib/reamaze_api/version.rb
|
123
124
|
- reamaze_api.gemspec
|
124
125
|
homepage: https://github.com/itspriddle/reamaze_api
|
125
|
-
licenses:
|
126
|
+
licenses:
|
127
|
+
- MIT
|
126
128
|
metadata: {}
|
127
129
|
post_install_message:
|
128
130
|
rdoc_options: []
|
@@ -145,4 +147,3 @@ signing_key:
|
|
145
147
|
specification_version: 4
|
146
148
|
summary: Reamaze API client
|
147
149
|
test_files: []
|
148
|
-
has_rdoc:
|