fulcrum 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +8 -8
  2. data/LICENSE +2 -2
  3. data/README.md +189 -70
  4. data/Rakefile +5 -0
  5. data/fulcrum.gemspec +2 -3
  6. data/lib/fulcrum.rb +22 -14
  7. data/lib/fulcrum/actions/create.rb +15 -0
  8. data/lib/fulcrum/actions/delete.rb +12 -0
  9. data/lib/fulcrum/actions/find.rb +11 -0
  10. data/lib/fulcrum/actions/list.rb +19 -0
  11. data/lib/fulcrum/actions/update.rb +11 -0
  12. data/lib/fulcrum/changeset.rb +12 -0
  13. data/lib/fulcrum/choice_list.rb +6 -35
  14. data/lib/fulcrum/classification_set.rb +6 -36
  15. data/lib/fulcrum/client.rb +120 -0
  16. data/lib/fulcrum/form.rb +6 -35
  17. data/lib/fulcrum/layer.rb +6 -0
  18. data/lib/fulcrum/media_resource.rb +47 -0
  19. data/lib/fulcrum/membership.rb +5 -0
  20. data/lib/fulcrum/page.rb +17 -0
  21. data/lib/fulcrum/photo.rb +9 -29
  22. data/lib/fulcrum/project.rb +3 -9
  23. data/lib/fulcrum/record.rb +6 -35
  24. data/lib/fulcrum/resource.rb +40 -0
  25. data/lib/fulcrum/signature.rb +15 -0
  26. data/lib/fulcrum/version.rb +1 -1
  27. data/lib/fulcrum/video.rb +23 -0
  28. data/spec/client_helper.rb +9 -0
  29. data/spec/data/test.jpg +0 -0
  30. data/spec/data/test.mp4 +0 -0
  31. data/spec/data/test.png +0 -0
  32. data/spec/lib/choice_list_spec.rb +10 -115
  33. data/spec/lib/classification_set_spec.rb +11 -114
  34. data/spec/lib/client_spec.rb +9 -0
  35. data/spec/lib/form_spec.rb +10 -111
  36. data/spec/lib/layer_spec.rb +13 -0
  37. data/spec/lib/membership_spec.rb +12 -0
  38. data/spec/lib/photo_spec.rb +9 -88
  39. data/spec/lib/project_spec.rb +7 -23
  40. data/spec/lib/record_spec.rb +10 -115
  41. data/spec/lib/signature_spec.rb +16 -0
  42. data/spec/lib/video_spec.rb +16 -0
  43. data/spec/resource_examples.rb +147 -0
  44. data/spec/spec_helper.rb +2 -0
  45. metadata +37 -41
  46. data/.rvmrc +0 -1
  47. data/lib/fulcrum/api.rb +0 -99
  48. data/lib/fulcrum/member.rb +0 -16
  49. data/lib/fulcrum/validators/base_validator.rb +0 -31
  50. data/lib/fulcrum/validators/choice_list_validator.rb +0 -30
  51. data/lib/fulcrum/validators/classification_set_validator.rb +0 -38
  52. data/lib/fulcrum/validators/form_validator.rb +0 -150
  53. data/lib/fulcrum/validators/record_validator.rb +0 -18
  54. data/spec/data/form_data.json +0 -175
  55. data/spec/lib/api_spec.rb +0 -42
  56. data/spec/lib/member_spec.rb +0 -52
  57. data/spec/lib/validators/choice_list_validator_spec.rb +0 -73
  58. data/spec/lib/validators/classification_set_validator_spec.rb +0 -88
  59. data/spec/lib/validators/form_validator_spec.rb +0 -4
  60. data/spec/lib/validators/record_validator_spec.rb +0 -53
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWY2MDkwMWM5ZWI3NjUxNzExMTQxNzRhYTNmMjg0OGJjNDdkNDhmNA==
4
+ NWFhOTc0Yzc4YzEzODQ2ZjE5MWVmMDI3NDc5MmU1Yjg1MDA3NzY1NQ==
5
5
  data.tar.gz: !binary |-
6
- YzU0ZWNhZmE4ODc1MmViYjVlMTI1NjVjM2M0Y2QxMDBjYTgxNWYyZg==
6
+ NDIyNjg1Yzg0MzMwNDFmNThiMTgyNjM1MWNkNzkyMmZhZjkxYWQwNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjA2NjdiM2JkNDViMGEzODQ5OWU1N2MzMzc3NmI0YzNhNDlhYzBhNDY4NDhm
10
- N2RiNGM4NjM1ZjNkMjAxNzZmZjgwNDdiNWQ1ZDBmZTMzYTJjYzA2MDA2N2M3
11
- ZTg2NmIwMTc0OTJjZjM1ZTdlNDZiNzhmNzAwNzU0OTFlYjIwNzE=
9
+ OGYxYjYxYWEzMWMwNWNhYTJhMWZiZjUyMTZhYzZlZjlhZGE2MjY3MGZlYTE2
10
+ MmY3ZjNiYjgzM2FmYTVmMGIzODliMzhmMzM0Yzg3NGY1MTIzYjA0YjIzZTdj
11
+ MWNkNGE5NzE1MDhhZGZmZTIzNjFhMzc1MTNjYWIzYzRhOGY3Y2I=
12
12
  data.tar.gz: !binary |-
13
- MTRkOTIwNzQwNDI5YjFiZTE4ZTc0YzkyZWU0ZWEyMThlMDRkNjRkYzA4YzUx
14
- MzAwZTkyOGRiMmRlMjM2N2M3MDgzYjVlNDhjZjExMGIxYjJmYWZiNTZmMWYx
15
- ZTU0MTNjYjE5MjBhODExNjliZmZlNTliNzRlYjc2NDFmYjhkMTU=
13
+ ZWYzNGE3NGUyZWNiMjBlMzY1MGJmMzE2MGZmYjVkZGYwN2YxODhjMjk5MWI3
14
+ OTk0NWQyMzNiNzcyMjQwOWNmYzkzMmMyNTI2Mzk4MjAzNGIyMTBmZTdjNzVj
15
+ NDg4NzMzNDU3YzBkYmQ5ZGY2NjE1M2NhMTE2YjAyMTdlMDRjNzM=
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Chris Hall
1
+ Copyright (c) 2014 Spatial Networks
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -5,7 +5,7 @@ Fulcrum API Gem
5
5
  ## Requirements
6
6
 
7
7
  * Ruby 1.9
8
- * [Fulcrum user account](https://web.fulcrumapp.com)
8
+ * [Fulcrum account](https://web.fulcrumapp.com)
9
9
 
10
10
  ## Installation
11
11
 
@@ -23,118 +23,237 @@ Or install it yourself as:
23
23
 
24
24
  gem install fulcrum
25
25
 
26
- ## Configuration
26
+ ## Using the gem
27
27
 
28
- ```ruby
29
- Fulcrum::Api.configure do |config|
30
- config.uri = 'https://api.fulcrumapp.com/api/v2'
31
- config.key = 'your_api_key'
32
- end
33
- ```
28
+ ## Client
34
29
 
35
- ## Projects
30
+ All interaction with the API is done through a client object. Below is a simple example of how to instantiate a client object.
36
31
 
37
32
  ```ruby
38
- Fulcrum::Project.all(opts)
39
- # opts = { 'page' => page_number,
40
- # 'updated_since' => date_time }
33
+ client = Fulcrum::Client.new(your_api_key)
41
34
  ```
42
35
 
43
- ## Forms
44
36
 
45
- ```ruby
46
- Fulcrum::Form.all(opts)
47
- # opts = { 'page' => page_number,
48
- # 'schema' => true_or_false }
37
+ ## Basics
49
38
 
50
- Fulcrum::Form.find(id, opts)
51
- # opts = { 'include_foreign_elements' => true_or_false }
39
+ In general, this API is intended to be a low level wrapper around the Fulcrum API. All of the filtering and query parameters are passed directly through to the HTTP request. It's best to read the [API documentation](http://fulcrumapp.com/developers/api/) to get a sense of the parameters available for each resource. Resource instances are returned from the API as simple hashes.
52
40
 
53
- Fulcrum::Form.create(form)
54
- # form = { 'form' => { ... } }
41
+ When using the `create` or `update` methods on resources, the object passed to the method should be in the same format as a result from calling `find` on that resource. For example, you can call `client.records.find(id)` and the result can be used as the parameter for `client.records.update(id, record)`.
55
42
 
56
- Fulcrum::Form.update(id, form)
57
- # form = { 'form' => { ... } }
43
+ Each of the API resources has an `all` method that can be used to fetch a list of resources. The `all` methods accept some basic pagination parameters (`per_page` and `page`) you can use to iterate over the pages. Because the index API's are paginated, the result of `all` is not the objects themselves. The `all` methods return a `Page` object that has some basic attributes to inspect the pagination extents. The `objects` attribute returns the actual array of objects. Below is a simple example that fetches the first page of records from the API.
44
+ ```ruby
58
45
 
59
- Fulcrum::Form.delete(id)
46
+ client = Fulcrum::Client.new(your_api_key)
47
+
48
+ result = client.records.all(form_id: my_form_id, page: 1, per_page: 100)
49
+
50
+ puts result.class # Fulcrum::Page
51
+ puts result.per_page # => 100
52
+ puts result.current_page # => 1
53
+ puts result.total_pages # => 2
54
+ puts result.total_count # => 137
55
+ puts result.objects.count # => 100
56
+ puts result.objects # [ ... the records ... ]
60
57
  ```
61
58
 
62
59
  ## Records
63
60
 
61
+ ### client.records.all(params = {})
62
+
63
+ Retrieve records with optional parameters. For a full list of the available parameters, see the [API documentation](http://fulcrumapp.com/developers/api/records/).
64
+
64
65
  ```ruby
65
- Fulcrum::Record.all(opts)
66
- # opts = { 'page' => page_number,
67
- # 'form_id' => form_id,
68
- # 'bounding_box' => 'lat_bottom,lng_left,lat_top,lng_right',
69
- # 'updated_since' => date_since_epoch_in_seconds }
66
+ client.records.all(page: 1, per_page: 100, form_id: some_form_id, updated_since: timestamp)
67
+ ```
70
68
 
71
- Fulcrum::Record.find(id)
72
- Fulcrum::Record.create(record)
73
- # record = { 'record' => { ... } }
69
+ ### client.records.find(id)
74
70
 
75
- Fulcrum::Record.update(id, record)
76
- # record = { 'record' => { ... } }
71
+ Find a single record by its `id` and return a `Hash` of the record attributes.
77
72
 
78
- Fulcrum::Record.delete(id)
79
- ```
73
+ ### client.records.create(record)
80
74
 
81
- ## Photos
75
+ Create a new record from a `Hash` of attributes. The format of the attributes is identical to the format returned from `find`. The [record API documentation](http://fulcrumapp.com/developers/api/records) has more information on the format. **Note:** although the raw API uses a hash wrapped in a `record` attribute, this is not necessary for the ruby API. Instead of `{ "record" => record_attributes }`, you simply pass `record_attributes` directly to this method.
82
76
 
83
- ```ruby
84
- Fulcrum::Photo.find(access_key, opts)
85
- # opts = { 'format' => 'json|jpg' }, defaults to 'json'
77
+ ### client.records.update(id, record)
86
78
 
87
- Fulcrum::Photo.thumbnail(access_key, opts)
88
- # opts = { 'format' => 'json|jpg' }, defaults to 'json'
79
+ Update an existing record by its `id` using a `Hash` of attributes. The format of the attributes is identical to the format returned from `find`. The [record API documentation](http://fulcrumapp.com/developers/api/records) has more information on the format. **Note:** although the raw API uses a hash wrapped in a `record` attribute, this is not necessary for the ruby API. Instead of `{ "record" => record_attributes }`, you simply pass `record_attributes` directly to this method.
80
+
81
+ ### client.records.delete(id)
82
+
83
+ Delete a record by its `id`.
84
+
85
+
86
+
87
+ ## Forms
88
+
89
+ ### client.forms.all(params = {})
90
+
91
+ ### client.forms.find(id)
92
+
93
+ ### client.forms.create(form)
94
+
95
+ ### client.forms.update(id, form)
96
+
97
+ ### client.forms.delete(id)
89
98
 
90
- Fulcrum::Photo.create(photo, content_type, unique_id, label)
91
99
 
92
- Fulcrum::Photo.delete(access_key)
93
- ```
94
100
 
95
101
  ## Choice Lists
96
102
 
97
- ```ruby
98
- Fulcrum::ChoiceList.all(opts)
99
- # opts = { 'page' => page_number }
103
+ ### client.choice_lists.all(params = {})
100
104
 
101
- Fulcrum::ChoiceList.find(id)
105
+ ### client.choice_lists.find(id)
102
106
 
103
- Fulcrum::ChoiceList.create(choice_list)
104
- # choice_list = { 'choice_list' => { ... } }
107
+ ### client.choice_lists.create(choice_list)
108
+
109
+ ### client.choice_lists.update(id, choice_list)
110
+
111
+ ### client.choice_lists.delete(id)
105
112
 
106
- Fulcrum::ChoiceList.update(id, choice_list)
107
- # choice_list = { 'choice_list' => { ... } }
108
113
 
109
- Fulcrum::ChoiceList.delete(id)
110
- ```
111
114
 
112
115
  ## Classification Sets
113
116
 
114
- ```ruby
115
- Fulcrum::ClassificationSet.all(opts)
116
- # opts = { 'page' => page_number }
117
+ ### client.classification_sets.all(params = {})
117
118
 
118
- Fulcrum::ClassificationSet.find(id)
119
+ ### client.classification_sets.find(id)
119
120
 
120
- Fulcrum::ClassificationSet.create(classification_set)
121
- # classification_set = { 'classification_set' => { ... } }
121
+ ### client.classification_sets.create(classification_set)
122
122
 
123
- Fulcrum::ClassificationSet.update(id, classification_set)
124
- # classification_set = { 'classification_set' => { ... } }
123
+ ### client.classification_sets.update(id, classification_set)
125
124
 
126
- Fulcrum::ClassificationSet.delete(id)
127
- ```
125
+ ### client.classification_sets.delete(id)
128
126
 
129
- ## Members
130
127
 
131
- ```ruby
132
- Fulcrum::Member.all(opts)
133
- # opts = { 'page' => page_number }
134
128
 
135
- Fulcrum::Member.find(id)
129
+ ## Projects
130
+
131
+ ### client.projects.all(params = {})
132
+
133
+ ### client.projects.find(id)
134
+
135
+
136
+
137
+ ## Layers
138
+
139
+ ### client.layers.all(params = {})
140
+
141
+ ### client.layers.find(id)
142
+
143
+
144
+
145
+ ## Photos
146
+
147
+ ### client.photos.all(params = {})
148
+
149
+ ### client.photos.find(id)
150
+
151
+ ### client.photos.create(file_or_path, content_type = 'image/jpeg', attributes = {})
152
+
153
+ Create a new photo from a file or a file path. `attributes` must be a `Hash` and currently only accepts 1 attribute, `access_key`.
154
+ If you specify an `access_key`, it must be a UUID. If you don't specify an `access_key`, one will be automatically generated and returned in the response.
155
+
156
+ ### client.photos.delete(id)
157
+
158
+ ### client.photos.original(id) {|io| block }
159
+
160
+ Downloads the original version and yields an IO object to the block. The block is passed an IO object that you can call `#read` on. For example, to download a photo to a file:
161
+
162
+ ```ruby
163
+ client.photos.original(id) do |input|
164
+ File.open('output.jpg', 'wb') do |output|
165
+ output.write(input.read)
166
+ end
167
+ end
136
168
  ```
137
169
 
170
+ ### client.photos.thumbnail(id) {|io| block }
171
+
172
+ Downloads the thumbnail version and yields an IO object to the block.
173
+
174
+ ### client.photos.large(id) {|io| block }
175
+
176
+ Downloads the large version and yields an IO object to the block.
177
+
178
+
179
+
180
+ ## Signatures
181
+
182
+ ### client.signatures.all(params = {})
183
+
184
+ ### client.signatures.find(id)
185
+
186
+ ### client.signatures.create(file_or_path, content_type = 'image/png', attributes = {})
187
+
188
+ Create a new signature from a file or a file path. `attributes` must be a `Hash` and currently only accepts 1 attribute, `access_key`.
189
+ If you specify an `access_key`, it must be a UUID. If you don't specify an `access_key`, one will be automatically generated and returned in the response.
190
+
191
+ ### client.signatures.delete(id)
192
+
193
+ ### client.signatures.original(id) {|io| block }
194
+
195
+ Downloads the original version and yields an IO object to the block.
196
+
197
+ ### client.signatures.thumbnail(id) {|io| block }
198
+
199
+ Downloads the thumbnail version and yields an IO object to the block.
200
+
201
+ ### client.signatures.large(id) {|io| block }
202
+
203
+ Downloads the large version and yields an IO object to the block.
204
+
205
+
206
+
207
+ ## Videos
208
+
209
+ ### client.videos.all(params = {})
210
+
211
+ ### client.videos.find(id)
212
+
213
+ ### client.videos.create(file_or_path, content_type = 'video/mp4', attributes = {})
214
+
215
+ Create a new video from a file or a file path. `attributes` must be a `Hash` and currently only accepts 2 attributes, `access_key` and `track`.
216
+ If you specify an `access_key`, it must be a UUID. If you don't specify an `access_key`, one will be automatically generated and returned in the response.
217
+
218
+ ### client.videos.delete(id)
219
+
220
+ ### client.videos.original(id) {|io| block }
221
+
222
+ Downloads the original version and yields an IO object to the block.
223
+
224
+ ### client.videos.small(id) {|io| block }
225
+
226
+ Downloads the small version and yields an IO object to the block.
227
+
228
+ ### client.videos.medium(id) {|io| block }
229
+
230
+ Downloads the medium version and yields an IO object to the block.
231
+
232
+ ### client.videos.track(id)
233
+
234
+ Fetches the GPS track for the specified video.
235
+
236
+
237
+
238
+ ## Memberships
239
+
240
+ ### client.memberships.all(params = {})
241
+
242
+
243
+
244
+ ## Changesets
245
+
246
+ ### client.changesets.all(params = {})
247
+
248
+ ### client.changesets.find(id)
249
+
250
+ ### client.changesets.create(changeset)
251
+
252
+ ### client.changesets.update(id, changeset)
253
+
254
+ ### client.changesets.close(id, changeset = {})
255
+
256
+
138
257
  ## Extra Reading
139
258
 
140
259
  * [Fulcrum API documentation](http://fulcrumapp.com/developers/api/)
data/Rakefile CHANGED
@@ -6,3 +6,8 @@ RSpec::Core::RakeTask.new
6
6
 
7
7
  task :default => :spec
8
8
  task :test => :spec
9
+
10
+ desc "Open an irb session preloaded with this library"
11
+ task :console do
12
+ sh "irb -rubygems -I lib -r fulcrum.rb"
13
+ end
data/fulcrum.gemspec CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |gem|
5
5
  gem.authors = ["Spatial Networks"]
6
6
  gem.email = ["sniadmin@spatialnetworks.com"]
7
7
  gem.description = %q{Fulcrum API}
8
- gem.summary = %q{Fulcrum API}
8
+ gem.summary = %q{Fulcrum API client for ruby}
9
9
  gem.homepage = "http://github.com/spatialnetworks/fulcrum-ruby"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
@@ -21,7 +21,6 @@ Gem::Specification.new do |gem|
21
21
  gem.add_development_dependency 'debugger'
22
22
 
23
23
  gem.add_dependency 'activesupport'
24
- gem.add_dependency 'faraday', '~> 0.8.8'
25
- gem.add_dependency 'hashie'
24
+ gem.add_dependency 'faraday', '~> 0.9.0'
26
25
  gem.add_dependency 'faraday_middleware'
27
26
  end
data/lib/fulcrum.rb CHANGED
@@ -1,14 +1,22 @@
1
- require "fulcrum/version"
2
- require "fulcrum/api"
3
- require "fulcrum/form"
4
- require "fulcrum/record"
5
- require "fulcrum/project"
6
- require "fulcrum/choice_list"
7
- require "fulcrum/classification_set"
8
- require "fulcrum/member"
9
- require "fulcrum/photo"
10
- require "fulcrum/validators/base_validator"
11
- require "fulcrum/validators/form_validator"
12
- require "fulcrum/validators/record_validator"
13
- require "fulcrum/validators/choice_list_validator"
14
- require "fulcrum/validators/classification_set_validator"
1
+ require 'active_support/all'
2
+ require 'fulcrum/version'
3
+ require 'fulcrum/resource'
4
+ require 'fulcrum/actions/list'
5
+ require 'fulcrum/actions/find'
6
+ require 'fulcrum/actions/create'
7
+ require 'fulcrum/actions/update'
8
+ require 'fulcrum/actions/delete'
9
+ require 'fulcrum/media_resource'
10
+ require 'fulcrum/page'
11
+ require 'fulcrum/choice_list'
12
+ require 'fulcrum/classification_set'
13
+ require 'fulcrum/form'
14
+ require 'fulcrum/membership'
15
+ require 'fulcrum/photo'
16
+ require 'fulcrum/video'
17
+ require 'fulcrum/signature'
18
+ require 'fulcrum/project'
19
+ require 'fulcrum/record'
20
+ require 'fulcrum/layer'
21
+ require 'fulcrum/changeset'
22
+ require 'fulcrum/client'
@@ -0,0 +1,15 @@
1
+ module Fulcrum
2
+ module Actions
3
+ module Create
4
+ extend ActiveSupport::Concern
5
+
6
+ def create_action
7
+ collection
8
+ end
9
+
10
+ def create(object)
11
+ call(:post, create_action, attributes_for_object(object))[resource_name]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module Fulcrum
2
+ module Actions
3
+ module Delete
4
+ extend ActiveSupport::Concern
5
+
6
+ def delete(id)
7
+ call(:delete, member(id))
8
+ end
9
+ end
10
+ end
11
+ end
12
+