gather_content-api 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.travis.yml +4 -0
- data/Gemfile +13 -0
- data/README.md +395 -0
- data/Rakefile +14 -0
- data/gather_content-api.gemspec +25 -0
- data/lib/gather_content/api/account.rb +25 -0
- data/lib/gather_content/api/accounts.rb +23 -0
- data/lib/gather_content/api/base.rb +67 -0
- data/lib/gather_content/api/config.rb +35 -0
- data/lib/gather_content/api/file.rb +19 -0
- data/lib/gather_content/api/files.rb +27 -0
- data/lib/gather_content/api/item.rb +53 -0
- data/lib/gather_content/api/items.rb +50 -0
- data/lib/gather_content/api/me.rb +19 -0
- data/lib/gather_content/api/project.rb +25 -0
- data/lib/gather_content/api/projects.rb +51 -0
- data/lib/gather_content/api/status.rb +26 -0
- data/lib/gather_content/api/statuses.rb +27 -0
- data/lib/gather_content/api/template.rb +25 -0
- data/lib/gather_content/api/templates.rb +35 -0
- data/lib/gather_content/api.rb +19 -0
- data/lib/gather_content/error/request_error.rb +33 -0
- data/lib/gather_content/error.rb +5 -0
- data/lib/gather_content/version.rb +3 -0
- data/lib/gather_content.rb +5 -0
- data/spec/gather_content/api/account_spec.rb +28 -0
- data/spec/gather_content/api/accounts_spec.rb +24 -0
- data/spec/gather_content/api/base_spec.rb +5 -0
- data/spec/gather_content/api/config_spec.rb +98 -0
- data/spec/gather_content/api/files_spec.rb +39 -0
- data/spec/gather_content/api/item_spec.rb +158 -0
- data/spec/gather_content/api/items_spec.rb +127 -0
- data/spec/gather_content/api/me_spec.rb +26 -0
- data/spec/gather_content/api/project_spec.rb +32 -0
- data/spec/gather_content/api/projects_spec.rb +96 -0
- data/spec/gather_content/api/status_spec.rb +44 -0
- data/spec/gather_content/api/statuses_spec.rb +39 -0
- data/spec/gather_content/api/template_spec.rb +36 -0
- data/spec/gather_content/api/templates_spec.rb +23 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/vcr_cassettes/GatherContent_Api_Account/_/returns_the_data_related_to_the_supplied_key.yml +39 -0
- data/spec/vcr_cassettes/GatherContent_Api_Account/_fetch/1_2_1.yml +39 -0
- data/spec/vcr_cassettes/GatherContent_Api_Account/_fetch/1_3_1.yml +39 -0
- data/spec/vcr_cassettes/GatherContent_Api_Account/_get_account/1_3_1.yml +39 -0
- data/spec/vcr_cassettes/GatherContent_Api_Accounts/_each/should_contain_Account_objects.yml +40 -0
- data/spec/vcr_cassettes/GatherContent_Api_Accounts/_each/should_have_memoized_data.yml +40 -0
- data/spec/vcr_cassettes/GatherContent_Api_Files/_each/should_contain_File_objects.yml +40 -0
- data/spec/vcr_cassettes/GatherContent_Api_Files/_each/should_have_memoized_data.yml +40 -0
- data/spec/vcr_cassettes/GatherContent_Api_Item/_/returns_the_data_related_to_the_supplied_key.yml +40 -0
- data/spec/vcr_cassettes/GatherContent_Api_Item/_fetch/1_2_1.yml +40 -0
- data/spec/vcr_cassettes/GatherContent_Api_Item/_get_item/1_3_1.yml +40 -0
- data/spec/vcr_cassettes/GatherContent_Api_Item/apply_template/successful/returns_true.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Item/apply_template/unsuccessful/parses_the_message.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Item/apply_template/unsuccessful/raises_an_RequestError.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Item/apply_template/unsuccessful/sets_the_RequestError_status.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Item/choose_status/successful/returns_true.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Item/choose_status/unsuccessful/parses_the_message.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Item/choose_status/unsuccessful/raises_an_RequestError.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Item/choose_status/unsuccessful/sets_the_RequestError_status.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Item/save/successful/returns_true.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Item/save/unsuccessful/parses_the_message.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Item/save/unsuccessful/raises_an_RequestError.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Item/save/unsuccessful/sets_the_RequestError_status.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Items/_create/on_non-202_response/raises_an_RequestError.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Items/_create/on_non-202_response/sets_the_RequestError_message.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Items/_create/on_non-202_response/sets_the_RequestError_status.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Items/_create/with_config/created_an_item.yml +44 -0
- data/spec/vcr_cassettes/GatherContent_Api_Items/_create/with_config/set_the_item_id.yml +44 -0
- data/spec/vcr_cassettes/GatherContent_Api_Items/_create/with_config/sets_the_content.yml +88 -0
- data/spec/vcr_cassettes/GatherContent_Api_Items/_create/with_name/created_an_item.yml +44 -0
- data/spec/vcr_cassettes/GatherContent_Api_Items/_create/with_name/set_the_item_id.yml +44 -0
- data/spec/vcr_cassettes/GatherContent_Api_Items/_each/should_contain_Item_objects.yml +43 -0
- data/spec/vcr_cassettes/GatherContent_Api_Items/_each/should_have_memoized_data.yml +43 -0
- data/spec/vcr_cassettes/GatherContent_Api_Me/_/returns_the_data_related_to_the_supplied_key.yml +40 -0
- data/spec/vcr_cassettes/GatherContent_Api_Me/_fetch/1_2_1.yml +40 -0
- data/spec/vcr_cassettes/GatherContent_Api_Me/_get_me/1_2_1.yml +40 -0
- data/spec/vcr_cassettes/GatherContent_Api_Project/_/returns_the_data_related_to_the_supplied_key.yml +41 -0
- data/spec/vcr_cassettes/GatherContent_Api_Project/_fetch/1_3_1.yml +41 -0
- data/spec/vcr_cassettes/GatherContent_Api_Project/_get_project/1_3_1.yml +41 -0
- data/spec/vcr_cassettes/GatherContent_Api_Projects/_create/on_non-202_response/raises_an_RequestError.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Projects/_create/on_non-202_response/sets_the_RequestError_message.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Projects/_create/on_non-202_response/sets_the_RequestError_status.yml +42 -0
- data/spec/vcr_cassettes/GatherContent_Api_Projects/_create/with_empty_type/created_a_project.yml +44 -0
- data/spec/vcr_cassettes/GatherContent_Api_Projects/_create/with_name_and_valid_type/created_a_project.yml +44 -0
- data/spec/vcr_cassettes/GatherContent_Api_Projects/_create/with_name_and_valid_type/set_the_project_id.yml +44 -0
- data/spec/vcr_cassettes/GatherContent_Api_Projects/_create/with_no_type/created_a_project.yml +44 -0
- data/spec/vcr_cassettes/GatherContent_Api_Projects/_each/should_contain_Project_objects.yml +41 -0
- data/spec/vcr_cassettes/GatherContent_Api_Status/_/returns_the_data_related_to_the_supplied_key.yml +39 -0
- data/spec/vcr_cassettes/GatherContent_Api_Status/_fetch/1_2_1.yml +39 -0
- data/spec/vcr_cassettes/GatherContent_Api_Statuses/_each/should_contain_Status_objects.yml +40 -0
- data/spec/vcr_cassettes/GatherContent_Api_Statuses/_each/should_have_memoized_data.yml +41 -0
- data/spec/vcr_cassettes/GatherContent_Api_Template/_/returns_the_data_related_to_the_supplied_key.yml +40 -0
- data/spec/vcr_cassettes/GatherContent_Api_Template/_fetch/1_2_1.yml +40 -0
- data/spec/vcr_cassettes/GatherContent_Api_Templates/_each/should_contain_Template_objects.yml +40 -0
- data/spec/vcr_cassettes/GatherContent_Api_Templates/_each/should_have_memoized_data.yml +40 -0
- metadata +254 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bc4fa4c68863fe799d804ff07fe209eff1e8893b
|
4
|
+
data.tar.gz: fe246d59f62d044e5fb78fc75204490dd8596dcc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1163d48c41a4648d40550e237b4d5f8a58e9b3e63ccf8a526880e1bbf8c1c1cd55588937f28975b947eff64751bd25cfab03e6f13456ac84dd5702e0bb8b0b17
|
7
|
+
data.tar.gz: affabeb1a6be1740294f12aad415688305dbc08a0f46949a8d60be34ac719bd58647964817d3aa9cbc0c5ff2778bb9a472d452b354af00e4fe0ff608e4680b07
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
gemspec
|
3
|
+
|
4
|
+
group :development do
|
5
|
+
gem 'vcr', '~> 3'
|
6
|
+
gem 'webmock', '~> 3'
|
7
|
+
gem 'rspec', '~> 3'
|
8
|
+
gem 'coveralls', require: false
|
9
|
+
|
10
|
+
gem 'pry'
|
11
|
+
gem 'figs', require: false
|
12
|
+
gem 'climate_control', require: false
|
13
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,395 @@
|
|
1
|
+
# GatherContent Ruby Client
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/NYULibraries/gather_content-api.svg?branch=master)](https://travis-ci.org/NYULibraries/gather_content-api)
|
4
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/NYULibraries/gather_content-api.svg)](https://gemnasium.com/github.com/NYULibraries/gather_content-api)
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/ace52f297d3f4160799d/maintainability)](https://codeclimate.com/github/NYULibraries/gather_content-api/maintainability)
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/github/NYULibraries/gather_content-api/badge.svg?branch=master)](https://coveralls.io/github/NYULibraries/gather_content-api?branch=master)
|
7
|
+
|
8
|
+
This gem is a light wrapper around the [GatherContent API](https://docs.gathercontent.com/reference).
|
9
|
+
|
10
|
+
All the endpoints are represented by Objects. Collective Objects (ie Projects, Items etc) are Enumerable, allowing you to loop over them. Singular Objects act like Hashes, giving access to the data via keys.
|
11
|
+
|
12
|
+
You can access the underlying data of a Singular Object by using the ```#fetch``` method. The ```#fetch``` method will cache the result - if you want to clear the result, call ```#reset```
|
13
|
+
|
14
|
+
# Usage
|
15
|
+
|
16
|
+
## Authentication
|
17
|
+
|
18
|
+
There are two was to setup [authentication](https://docs.gathercontent.com/reference#authentication):
|
19
|
+
|
20
|
+
1. using the _Config_ object
|
21
|
+
2. via Environmental variables
|
22
|
+
|
23
|
+
### The Config Object
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
GatherContent::Api::Config.run do |config|
|
27
|
+
config.username = "Your GatherContent username"
|
28
|
+
config.api_key = "Your GatherContent API key"
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
### Environmental Variables
|
33
|
+
|
34
|
+
```bash
|
35
|
+
export GATHER_CONTENT_API_USERNAME="Your GatherContent username"
|
36
|
+
export GATHER_CONTENT_API_KEY="Your GatherContent API key"
|
37
|
+
ruby script_that_uses_the_gem.rb
|
38
|
+
```
|
39
|
+
|
40
|
+
## Me
|
41
|
+
|
42
|
+
You have access to all fields of information about the logged in User such as their avatar url, name, and other fields. [Sample Response](https://docs.gathercontent.com/reference#get-me)
|
43
|
+
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
require 'gather_content'
|
47
|
+
|
48
|
+
me = GatherContent::Api::Me.new
|
49
|
+
me["email"]
|
50
|
+
=> "andrew@gathercontent.com"
|
51
|
+
|
52
|
+
me["first_name"]
|
53
|
+
=> "Andrew"
|
54
|
+
```
|
55
|
+
|
56
|
+
## Accounts
|
57
|
+
|
58
|
+
Retrieves a list of all Accounts associated with the authenticated user. [Sample Response](https://docs.gathercontent.com/reference#get-accounts)
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
require 'gather_content'
|
62
|
+
|
63
|
+
accounts = GatherContent::Api::Accounts.new
|
64
|
+
accounts.each do |account|
|
65
|
+
puts account["id"]
|
66
|
+
puts account["name"]
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
## Account
|
71
|
+
|
72
|
+
Retrieve a specific account. [Sample Response](https://docs.gathercontent.com/reference#get-accountsaccount_id)
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
require 'gather_content'
|
76
|
+
|
77
|
+
account_id = 123456
|
78
|
+
accounts = GatherContent::Api::Account.new(account_id)
|
79
|
+
|
80
|
+
account["id"]
|
81
|
+
=> 123456
|
82
|
+
|
83
|
+
account["name"]
|
84
|
+
=> "Example"
|
85
|
+
```
|
86
|
+
|
87
|
+
## Projects
|
88
|
+
|
89
|
+
Retrieves a list of all Projects associated with the given Account. [Sample Response](https://docs.gathercontent.com/reference#get-projects)
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
require 'gather_content'
|
93
|
+
|
94
|
+
account_id = 123456
|
95
|
+
projects = GatherContent::Api::Projects.new(account_id)
|
96
|
+
|
97
|
+
projects.each do |project|
|
98
|
+
puts project["id"]
|
99
|
+
puts project["name"]
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
### Project
|
104
|
+
|
105
|
+
Retrieves all information for a specific Project. [Sample Response](https://docs.gathercontent.com/reference#get-project-by-id)
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
require 'gather_content'
|
109
|
+
|
110
|
+
project_id = 123456
|
111
|
+
project = GatherContent::Api::Project.new(project_id)
|
112
|
+
|
113
|
+
project["id"]
|
114
|
+
=> 123456
|
115
|
+
|
116
|
+
project["name"]
|
117
|
+
=> "Example Project"
|
118
|
+
```
|
119
|
+
|
120
|
+
### Creating a Project
|
121
|
+
|
122
|
+
Creates a new Project for a specific Account. When you create a Project, a default Workflow containing four Statuses will be created and associated with it. As part of this request a type can be passed as an argument to specify the project type.
|
123
|
+
|
124
|
+
Supported project types
|
125
|
+
|
126
|
+
* website-build
|
127
|
+
* ongoing-website-content
|
128
|
+
* marketing-editorial-content
|
129
|
+
* email-marketing-content
|
130
|
+
* other
|
131
|
+
|
132
|
+
If successful, will return the newly created project.
|
133
|
+
|
134
|
+
On failure, it will throw a GatherContent::Error::RequestError
|
135
|
+
|
136
|
+
[Sample Response](https://docs.gathercontent.com/reference#post-projects)
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
require 'gather_content'
|
140
|
+
|
141
|
+
account_id = 123456
|
142
|
+
|
143
|
+
begin
|
144
|
+
p = GatherContent::Api::Projects.new(account_id)
|
145
|
+
# Name is required. Type defaults to "other"
|
146
|
+
project = p.create{ "name" => "Project Name", "type" => "website-build" })
|
147
|
+
|
148
|
+
name = project["name"]
|
149
|
+
rescue GatherContent::Error::RequestError => e
|
150
|
+
puts e.message
|
151
|
+
end
|
152
|
+
```
|
153
|
+
|
154
|
+
### Statuses
|
155
|
+
|
156
|
+
Retrieves a list of all the Statuses (what we call the Project’s Workflow) associated with a given Project. This includes their names, descriptions, associated colours and their Due Dates. [Sample Response](https://docs.gathercontent.com/reference#get-project-statuses)
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
require 'gather_content'
|
160
|
+
|
161
|
+
project_id = 123456
|
162
|
+
statuses = GatherContent::Api::Statuses.new(project_id)
|
163
|
+
|
164
|
+
statuses.each do |status|
|
165
|
+
puts status["id"]
|
166
|
+
puts status["name"]
|
167
|
+
end
|
168
|
+
```
|
169
|
+
|
170
|
+
### Status
|
171
|
+
|
172
|
+
Retrieves a list of all the Statuses (what we call the Project’s Workflow) associated with a given Project. This includes their names, descriptions, associated colours and their Due Dates. [Sample Response](https://docs.gathercontent.com/reference#get-project-statuses-by-id)
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
require 'gather_content'
|
176
|
+
|
177
|
+
status_id = 123456
|
178
|
+
status = GatherContent::Api::Status.new(status_id)
|
179
|
+
|
180
|
+
status["id"]
|
181
|
+
=> 123456
|
182
|
+
|
183
|
+
status["name"]
|
184
|
+
=> "Draft"
|
185
|
+
```
|
186
|
+
|
187
|
+
## Items
|
188
|
+
|
189
|
+
Get a list of all Items that exist on a particular Project.
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
require 'gather_content'
|
193
|
+
|
194
|
+
project_id = 123456
|
195
|
+
items = GatherContent::Api::Items.new(project_id)
|
196
|
+
|
197
|
+
items.each do |item|
|
198
|
+
puts item["id"]
|
199
|
+
puts item["name"]
|
200
|
+
end
|
201
|
+
```
|
202
|
+
|
203
|
+
### Item
|
204
|
+
|
205
|
+
Get all data related to a particular Item within a Project. You can access all of its properties, including the content which will be separated by the different fields it contains.
|
206
|
+
|
207
|
+
```ruby
|
208
|
+
require 'gather_content'
|
209
|
+
|
210
|
+
item_id = 123456
|
211
|
+
item = GatherContent::Api::Item.new(item_id)
|
212
|
+
|
213
|
+
item["id"]
|
214
|
+
=> 123456
|
215
|
+
|
216
|
+
item["name"]
|
217
|
+
=> "Home"
|
218
|
+
```
|
219
|
+
|
220
|
+
### Create an item
|
221
|
+
|
222
|
+
Creates a new Item within a particular Project.
|
223
|
+
|
224
|
+
The config object (if supplied) should be a Ruby Hash representation of the [configuration](https://docs.gathercontent.com/reference#the-config-field).
|
225
|
+
|
226
|
+
If successful, will return the newly created item.
|
227
|
+
|
228
|
+
On failure, it will throw a GatherContent::Error::RequestError
|
229
|
+
|
230
|
+
```ruby
|
231
|
+
require 'gather_content'
|
232
|
+
|
233
|
+
project_id = 123456
|
234
|
+
|
235
|
+
config = [{
|
236
|
+
"label": "Content",
|
237
|
+
"name": "tab1",
|
238
|
+
"hidden": false,
|
239
|
+
"elements": [{
|
240
|
+
"type": "text",
|
241
|
+
"name": "el1",
|
242
|
+
"required": false,
|
243
|
+
"label": "Blog post",
|
244
|
+
"value": "Hello world",
|
245
|
+
"microcopy": "",
|
246
|
+
"limit_type": "words",
|
247
|
+
"limit": 1000,
|
248
|
+
"plain_text": false
|
249
|
+
}]
|
250
|
+
}]
|
251
|
+
|
252
|
+
begin
|
253
|
+
i = GatherContent::Api::Items.new(project_id)
|
254
|
+
item = i.create({
|
255
|
+
"name" => "Item Name", # Required
|
256
|
+
"parent_id" => 123456, # Optional
|
257
|
+
"template_id" => 123456, # Optional
|
258
|
+
"config" => config, # Optional
|
259
|
+
});
|
260
|
+
|
261
|
+
puts item["name"]
|
262
|
+
|
263
|
+
rescue GatherContent::Error::RequestError => e
|
264
|
+
puts e.message
|
265
|
+
end
|
266
|
+
```
|
267
|
+
|
268
|
+
### Save an item
|
269
|
+
|
270
|
+
Saves an Item with the newly updated data. It expects a valid configuration structure, otherwise the save request will not be accepted by the API.
|
271
|
+
|
272
|
+
The config object should be a Ruby Hash representation of the [configuration](https://docs.gathercontent.com/reference#the-config-field).
|
273
|
+
|
274
|
+
```ruby
|
275
|
+
require 'gather_content'
|
276
|
+
|
277
|
+
item_id = 123456
|
278
|
+
item = GatherContent::Api::Item.new(item_id)
|
279
|
+
|
280
|
+
config = [{
|
281
|
+
"label": "Content",
|
282
|
+
"name": "tab1",
|
283
|
+
"hidden": false,
|
284
|
+
"elements": [{
|
285
|
+
"type": "text",
|
286
|
+
"name": "el1",
|
287
|
+
"required": false,
|
288
|
+
"label": "Blog post",
|
289
|
+
"value": "Hello world",
|
290
|
+
"microcopy": "",
|
291
|
+
"limit_type": "words",
|
292
|
+
"limit": 1000,
|
293
|
+
"plain_text": false
|
294
|
+
}]
|
295
|
+
}]
|
296
|
+
|
297
|
+
begin
|
298
|
+
item.save(config)
|
299
|
+
rescue GatherContent::Error::RequestError => e
|
300
|
+
puts e.message
|
301
|
+
end
|
302
|
+
```
|
303
|
+
|
304
|
+
On failure, it will throw a GatherContent::Error::RequestError
|
305
|
+
|
306
|
+
### Apply a template to an item
|
307
|
+
|
308
|
+
Applies the structure of a Template to an existing Item.
|
309
|
+
|
310
|
+
Beware that, just like within the application, this action will override the existing structure of an Item and may result in loss of content when fields do not match. Ensure you take necessary precautions.
|
311
|
+
|
312
|
+
```ruby
|
313
|
+
require 'gather_content'
|
314
|
+
|
315
|
+
item_id = 123456
|
316
|
+
item = GatherContent::Api::Item.new(item_id)
|
317
|
+
|
318
|
+
template_id = 123456
|
319
|
+
begin
|
320
|
+
item.apply_template(template_id)
|
321
|
+
rescue GatherContent::Error::RequestError => e
|
322
|
+
puts e.message
|
323
|
+
end
|
324
|
+
```
|
325
|
+
|
326
|
+
On failure, it will throw a GatherContent::Error::RequestError
|
327
|
+
|
328
|
+
### Choose Status
|
329
|
+
|
330
|
+
Set the status of the item
|
331
|
+
|
332
|
+
```ruby
|
333
|
+
require 'gather_content'
|
334
|
+
|
335
|
+
item_id = 123456
|
336
|
+
item = GatherContent::Api::Item.new(item_id)
|
337
|
+
|
338
|
+
status_id = 123456
|
339
|
+
begin
|
340
|
+
item.choose_status(status_id)
|
341
|
+
rescue GatherContent::Error::RequestError => e
|
342
|
+
puts e.message
|
343
|
+
end
|
344
|
+
```
|
345
|
+
|
346
|
+
On failure, it will throw a GatherContent::Error::RequestError
|
347
|
+
|
348
|
+
### Files
|
349
|
+
|
350
|
+
Get a list of all files related to a particular Item. [Sample Response](https://docs.gathercontent.com/reference#get-item-files)
|
351
|
+
|
352
|
+
```ruby
|
353
|
+
require 'gather_content'
|
354
|
+
|
355
|
+
item_id = 123456
|
356
|
+
files = GatherContent::Api::Files.new(item_id)
|
357
|
+
|
358
|
+
files.each do |file|
|
359
|
+
puts file["id"]
|
360
|
+
puts file["filename"]
|
361
|
+
end
|
362
|
+
```
|
363
|
+
|
364
|
+
## Templates
|
365
|
+
|
366
|
+
Retrieves a list of all Templates associated with the given Project. [Sample Response](https://docs.gathercontent.com/reference#get-templates)
|
367
|
+
|
368
|
+
```ruby
|
369
|
+
require 'gather_content'
|
370
|
+
|
371
|
+
project_id = 123456
|
372
|
+
templates = GatherContent::Api::Templates.new(project_id)
|
373
|
+
|
374
|
+
templates.each do |template|
|
375
|
+
puts template["id"]
|
376
|
+
puts template["name"]
|
377
|
+
end
|
378
|
+
```
|
379
|
+
|
380
|
+
### Template
|
381
|
+
|
382
|
+
This retrieves all data related with a specific Template. [Sample Response](https://docs.gathercontent.com/reference#get-template-by-id)
|
383
|
+
|
384
|
+
```ruby
|
385
|
+
require 'gather_content'
|
386
|
+
|
387
|
+
template_id = 123456
|
388
|
+
template = GatherContent::Api::Status.new(template_id)
|
389
|
+
|
390
|
+
template["id"]
|
391
|
+
=> 123456
|
392
|
+
|
393
|
+
template["name"]
|
394
|
+
=> "Blog theme"
|
395
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
Bundler::GemHelper.install_tasks
|
8
|
+
|
9
|
+
require 'rspec/core/rake_task'
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
11
|
+
task :default => :spec
|
12
|
+
|
13
|
+
# Load up all rake tasks in lib/tasks
|
14
|
+
Dir.glob('lib/tasks/*.rake').each { |r| import r }
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gather_content/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "gather_content-api"
|
8
|
+
gem.version = GatherContent::VERSION
|
9
|
+
gem.authors = ["Barnaby Alter", "Hannan Butt"]
|
10
|
+
gem.email = ["barnaby.alter@nyu.edu", "hab278@nyu.edu"]
|
11
|
+
gem.description = %q{Ruby wrapper for the GatherContent API}
|
12
|
+
gem.summary = %q{Ruby wrapper for the GatherContent API}
|
13
|
+
gem.homepage = "https://github.com/NYULibraries/gather_content-api"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.licenses = ['MIT']
|
20
|
+
|
21
|
+
gem.required_ruby_version = '>= 1.9.3'
|
22
|
+
gem.add_dependency 'rake', '~> 10'
|
23
|
+
gem.add_dependency 'rest-client', '~> 2'
|
24
|
+
gem.add_dependency 'faraday', '~> 0'
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module GatherContent
|
2
|
+
module Api
|
3
|
+
class Account < Base
|
4
|
+
attr_accessor :account_id
|
5
|
+
|
6
|
+
def initialize(account_id, data = nil)
|
7
|
+
raise ArgumentError, "account_id is required!" if account_id.nil?
|
8
|
+
@account_id = account_id
|
9
|
+
@data = data
|
10
|
+
end
|
11
|
+
|
12
|
+
def [](key)
|
13
|
+
fetch[key]
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def path
|
19
|
+
@path ||= "/accounts/#{account_id}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def params; end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module GatherContent
|
2
|
+
module Api
|
3
|
+
class Accounts < Base
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
def initialize; end
|
7
|
+
|
8
|
+
def each(&block)
|
9
|
+
fetch.each do |account|
|
10
|
+
yield GatherContent::Api::Account.new(account['id'], account)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def params; end
|
17
|
+
|
18
|
+
def path
|
19
|
+
@path ||= '/accounts'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module GatherContent
|
2
|
+
module Api
|
3
|
+
class Base
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
raise RuntimeError, "Cannot initialize this interface!"
|
7
|
+
end
|
8
|
+
|
9
|
+
def get(path_override = nil)
|
10
|
+
connection.get do |request|
|
11
|
+
request.url(path_override || path)
|
12
|
+
request.params = params unless params.nil?
|
13
|
+
request.headers['Accept'] = "application/vnd.gathercontent.v0.5+json"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def post(data = {}, path_override = nil)
|
18
|
+
connection.post do |request|
|
19
|
+
request.url(path_override || path)
|
20
|
+
request.body = data
|
21
|
+
request.headers['Accept'] = "application/vnd.gathercontent.v0.5+json"
|
22
|
+
yield request if block_given?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def post_json(data = {}, path_override = nil)
|
27
|
+
post(data.to_json, path_override) do |request|
|
28
|
+
request.headers['Content-type'] = "application/json"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def fetch
|
33
|
+
@data ||= parse(get.body)
|
34
|
+
end
|
35
|
+
|
36
|
+
def reset
|
37
|
+
@data = nil
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
def params
|
42
|
+
raise RuntimeError, "Expected this to be implemented in a subclass!"
|
43
|
+
end
|
44
|
+
|
45
|
+
def path
|
46
|
+
raise RuntimeError, "Expected this to be implemented in a subclass!"
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def parse(data)
|
51
|
+
parsed = JSON.parse(data)
|
52
|
+
parsed['data']
|
53
|
+
end
|
54
|
+
|
55
|
+
def connection
|
56
|
+
config = GatherContent::Api::Config.instance
|
57
|
+
|
58
|
+
@connection ||= Faraday.new(url: "#{config.host}:#{config.port}") do |faraday|
|
59
|
+
faraday.request :url_encoded
|
60
|
+
faraday.request :basic_auth, config.username, config.api_key
|
61
|
+
# faraday.response :logger
|
62
|
+
faraday.adapter Faraday.default_adapter
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module GatherContent
|
2
|
+
module Api
|
3
|
+
class Config
|
4
|
+
attr_writer :username, :api_key, :host, :port
|
5
|
+
|
6
|
+
def self.run
|
7
|
+
yield self.instance
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.instance
|
11
|
+
@instance ||= self.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def username
|
15
|
+
@username || ENV['GATHER_CONTENT_API_USERNAME']
|
16
|
+
end
|
17
|
+
|
18
|
+
def api_key
|
19
|
+
@api_key || ENV['GATHER_CONTENT_API_KEY']
|
20
|
+
end
|
21
|
+
|
22
|
+
def host
|
23
|
+
@host || ENV['GATHER_CONTENT_API_HOST'] || "https://api.gathercontent.com"
|
24
|
+
end
|
25
|
+
|
26
|
+
def port
|
27
|
+
@port || ENV['GATHER_CONTENT_API_PORT'] || "443"
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def initialize
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module GatherContent
|
2
|
+
module Api
|
3
|
+
class File < Base
|
4
|
+
attr_accessor :file_id
|
5
|
+
|
6
|
+
def initialize(item_id, file_id, data)
|
7
|
+
raise ArgumentError, "item_id is required!" if item_id.nil?
|
8
|
+
raise ArgumentError, "file_id is required!" if file_id.nil?
|
9
|
+
@item_id = item_id
|
10
|
+
@file_id = file_id
|
11
|
+
@data = data
|
12
|
+
end
|
13
|
+
|
14
|
+
def [](key)
|
15
|
+
@data[key]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module GatherContent
|
2
|
+
module Api
|
3
|
+
class Files < Base
|
4
|
+
attr_accessor :item_id
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def initialize(item_id)
|
8
|
+
raise ArgumentError, "item_id is required!" if item_id.nil?
|
9
|
+
@item_id = item_id
|
10
|
+
end
|
11
|
+
|
12
|
+
def each(&block)
|
13
|
+
fetch.each do |file|
|
14
|
+
yield GatherContent::Api::File.new(@item_id, file['id'], file)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def path
|
21
|
+
@path ||= "/items/#{item_id}/files"
|
22
|
+
end
|
23
|
+
|
24
|
+
def params; end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|