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
data/spec/spec_helper.rb CHANGED
@@ -2,4 +2,6 @@ require 'rspec'
2
2
  require 'webmock/rspec'
3
3
  require 'fulcrum'
4
4
  require 'debugger'
5
+ require 'client_helper'
6
+ require 'resource_examples'
5
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fulcrum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spatial Networks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-11 00:00:00.000000000 Z
11
+ date: 2014-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -86,28 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - ~>
88
88
  - !ruby/object:Gem::Version
89
- version: 0.8.8
89
+ version: 0.9.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ~>
95
95
  - !ruby/object:Gem::Version
96
- version: 0.8.8
97
- - !ruby/object:Gem::Dependency
98
- name: hashie
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ! '>='
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ! '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
96
+ version: 0.9.0
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: faraday_middleware
113
99
  requirement: !ruby/object:Gem::Requirement
@@ -130,41 +116,49 @@ extensions: []
130
116
  extra_rdoc_files: []
131
117
  files:
132
118
  - .gitignore
133
- - .rvmrc
134
119
  - Gemfile
135
120
  - LICENSE
136
121
  - README.md
137
122
  - Rakefile
138
123
  - fulcrum.gemspec
139
124
  - lib/fulcrum.rb
140
- - lib/fulcrum/api.rb
125
+ - lib/fulcrum/actions/create.rb
126
+ - lib/fulcrum/actions/delete.rb
127
+ - lib/fulcrum/actions/find.rb
128
+ - lib/fulcrum/actions/list.rb
129
+ - lib/fulcrum/actions/update.rb
130
+ - lib/fulcrum/changeset.rb
141
131
  - lib/fulcrum/choice_list.rb
142
132
  - lib/fulcrum/classification_set.rb
133
+ - lib/fulcrum/client.rb
143
134
  - lib/fulcrum/form.rb
144
- - lib/fulcrum/member.rb
135
+ - lib/fulcrum/layer.rb
136
+ - lib/fulcrum/media_resource.rb
137
+ - lib/fulcrum/membership.rb
138
+ - lib/fulcrum/page.rb
145
139
  - lib/fulcrum/photo.rb
146
140
  - lib/fulcrum/project.rb
147
141
  - lib/fulcrum/record.rb
148
- - lib/fulcrum/validators/base_validator.rb
149
- - lib/fulcrum/validators/choice_list_validator.rb
150
- - lib/fulcrum/validators/classification_set_validator.rb
151
- - lib/fulcrum/validators/form_validator.rb
152
- - lib/fulcrum/validators/record_validator.rb
142
+ - lib/fulcrum/resource.rb
143
+ - lib/fulcrum/signature.rb
153
144
  - lib/fulcrum/version.rb
154
- - spec/data/form_data.json
145
+ - lib/fulcrum/video.rb
146
+ - spec/client_helper.rb
155
147
  - spec/data/test.jpg
156
- - spec/lib/api_spec.rb
148
+ - spec/data/test.mp4
149
+ - spec/data/test.png
157
150
  - spec/lib/choice_list_spec.rb
158
151
  - spec/lib/classification_set_spec.rb
152
+ - spec/lib/client_spec.rb
159
153
  - spec/lib/form_spec.rb
160
- - spec/lib/member_spec.rb
154
+ - spec/lib/layer_spec.rb
155
+ - spec/lib/membership_spec.rb
161
156
  - spec/lib/photo_spec.rb
162
157
  - spec/lib/project_spec.rb
163
158
  - spec/lib/record_spec.rb
164
- - spec/lib/validators/choice_list_validator_spec.rb
165
- - spec/lib/validators/classification_set_validator_spec.rb
166
- - spec/lib/validators/form_validator_spec.rb
167
- - spec/lib/validators/record_validator_spec.rb
159
+ - spec/lib/signature_spec.rb
160
+ - spec/lib/video_spec.rb
161
+ - spec/resource_examples.rb
168
162
  - spec/spec_helper.rb
169
163
  homepage: http://github.com/spatialnetworks/fulcrum-ruby
170
164
  licenses: []
@@ -188,21 +182,23 @@ rubyforge_project:
188
182
  rubygems_version: 2.1.5
189
183
  signing_key:
190
184
  specification_version: 4
191
- summary: Fulcrum API
185
+ summary: Fulcrum API client for ruby
192
186
  test_files:
193
- - spec/data/form_data.json
187
+ - spec/client_helper.rb
194
188
  - spec/data/test.jpg
195
- - spec/lib/api_spec.rb
189
+ - spec/data/test.mp4
190
+ - spec/data/test.png
196
191
  - spec/lib/choice_list_spec.rb
197
192
  - spec/lib/classification_set_spec.rb
193
+ - spec/lib/client_spec.rb
198
194
  - spec/lib/form_spec.rb
199
- - spec/lib/member_spec.rb
195
+ - spec/lib/layer_spec.rb
196
+ - spec/lib/membership_spec.rb
200
197
  - spec/lib/photo_spec.rb
201
198
  - spec/lib/project_spec.rb
202
199
  - spec/lib/record_spec.rb
203
- - spec/lib/validators/choice_list_validator_spec.rb
204
- - spec/lib/validators/classification_set_validator_spec.rb
205
- - spec/lib/validators/form_validator_spec.rb
206
- - spec/lib/validators/record_validator_spec.rb
200
+ - spec/lib/signature_spec.rb
201
+ - spec/lib/video_spec.rb
202
+ - spec/resource_examples.rb
207
203
  - spec/spec_helper.rb
208
204
  has_rdoc:
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use ruby-1.9.3@fulcrum_api --create
data/lib/fulcrum/api.rb DELETED
@@ -1,99 +0,0 @@
1
- require 'faraday'
2
- require 'faraday_middleware'
3
-
4
- module Fulcrum
5
-
6
- class ApiError < Faraday::Error::ClientError; end
7
- class ConnectionError < StandardError; end
8
-
9
- class Api
10
-
11
- VALID_METHODS = [:get, :post, :put, :delete]
12
-
13
- attr :connection
14
- attr :response
15
- attr_writer :configuration
16
-
17
- class << self
18
-
19
- def key
20
- @configuration.key
21
- end
22
-
23
- def uri
24
- @configuration.uri
25
- end
26
-
27
- def response
28
- @response
29
- end
30
-
31
- def parse_opts(keys = [], opts = {})
32
- opts = opts.with_indifferent_access
33
- {}.tap do |p|
34
- keys.each { |key| p[key.to_sym] = opts[key] if opts.has_key?(key) }
35
- end
36
- end
37
-
38
- def call(method = :get, path = '', params = {})
39
- raise ArgumentError, "Invalid method: #{method.to_s}" unless VALID_METHODS.include?(method.to_sym)
40
- @response = connection.send(method.to_sym, path, params)
41
- @response.body
42
- rescue Faraday::Error::ClientError => e
43
- @response = e.response
44
- { error: { status: @response[:status], message: @response[:body] } }
45
- end
46
-
47
- def configure
48
- yield(configuration)
49
- end
50
-
51
- def configuration
52
- @configuration ||= Configuration.new
53
- end
54
-
55
- def connection
56
- if !@connection
57
- @connection = Faraday.new(Fulcrum::Api.configuration.uri) do |b|
58
- b.request :multipart
59
- b.request :json
60
- b.response :raise_error
61
- b.response :json , :content_type => 'application/json'
62
- b.adapter Faraday.default_adapter
63
- end
64
- @connection.headers['X-ApiToken'] = Fulcrum::Api.configuration.key
65
- @connection.headers['User-Agent'] = "Ruby Fulcrum API Client, Version #{Fulcrum::VERSION}"
66
- end
67
- @connection
68
- end
69
-
70
- def get_key(username, password)
71
- conn = Faraday.new(uri) do |b|
72
- b.request :url_encoded
73
- b.response :raise_error
74
- b.response :json, :content_type => "application/json"
75
- b.adapter Faraday.default_adapter
76
- end
77
-
78
- conn.headers['User-Agent'] = "Ruby Fulcrum API Client version #{Fulcrum::VERSION}"
79
- conn.basic_auth(username, password)
80
- resp = conn.get('users.json')
81
- body = JSON.parse(resp.body)
82
- if body['user']
83
- body['user']['api_token']
84
- else
85
- nil
86
- end
87
- end
88
- end
89
-
90
- class Configuration
91
- attr_accessor :uri
92
- attr_accessor :key
93
-
94
- def initialize
95
- self.uri = 'https://api.fulcrumapp.com/api/v2'
96
- end
97
- end
98
- end
99
- end
@@ -1,16 +0,0 @@
1
- module Fulcrum
2
- class Member < Api
3
-
4
- class << self
5
-
6
- def all(opts = {})
7
- params = parse_opts([:page], opts)
8
- call(:get, 'members.json', params)
9
- end
10
-
11
- def find(id)
12
- call(:get, "members/#{id}.json")
13
- end
14
- end
15
- end
16
- end
@@ -1,31 +0,0 @@
1
- require 'active_support/core_ext/hash'
2
-
3
- module Fulcrum
4
- class BaseValidator
5
- attr_accessor :data
6
- attr_accessor :errors
7
-
8
- def initialize(data)
9
- @data = (data.is_a?(Hash) ? data : JSON.parse(data)).with_indifferent_access
10
- @errors = {}
11
- validate!
12
- end
13
-
14
- def valid?
15
- errors.empty?
16
- end
17
-
18
- def add_error(key, data_name, error)
19
- if errors.has_key?(key)
20
- if errors[key].has_key?(data_name)
21
- errors[key][data_name].push(error)
22
- else
23
- errors[key][data_name] = [error]
24
- end
25
- else
26
- errors[key] = {}
27
- errors[key][data_name] = [error]
28
- end
29
- end
30
- end
31
- end
@@ -1,30 +0,0 @@
1
- module Fulcrum
2
- class ChoiceListValidator < BaseValidator
3
-
4
- def validate!
5
- if data['choice_list'].kind_of?(Hash) && !data['choice_list'].blank?
6
- add_error('choice_list', 'name', 'must not be blank') if data['choice_list']['name'].blank?
7
- choices(data['choice_list']['choices'])
8
- else
9
- @errors['choice_list'] = ['must be a non-empty hash']
10
- end
11
- return valid?
12
- end
13
-
14
- def choices(elements)
15
- if elements.kind_of?(Array) && !elements.empty?
16
- elements.each do |choice|
17
- if choice.blank?
18
- add_error('choices', 'choice', 'cannot be empty')
19
- else
20
- if choice['label'].blank?
21
- add_error('choice', 'label', 'is required')
22
- end
23
- end
24
- end
25
- else
26
- add_error('choice_list', 'choices', 'must be a non-empty array')
27
- end
28
- end
29
- end
30
- end
@@ -1,38 +0,0 @@
1
- module Fulcrum
2
- class ClassificationSetValidator < BaseValidator
3
-
4
- def validate!
5
- if data['classification_set']
6
- add_error('classification_set', 'name', 'cannot be blank') if data['classification_set']['name'].blank?
7
-
8
- if data['classification_set']['items'].blank? || !data['classification_set']['items'].kind_of?(Array)
9
- add_error('classification_set', 'items', 'must be a non-empty array')
10
- else
11
- items(data['classification_set']['items'])
12
- end
13
- else
14
- @errors['classification_set'] = ['must exist and not be blank']
15
- end
16
- return valid?
17
- end
18
-
19
- def items(elements, child = false)
20
- parent, child = child ? ['child_classification', 'item'] : ['items', 'item']
21
- if elements.kind_of?(Array) && !elements.empty?
22
- elements.each do |element|
23
- if element.blank?
24
- add_error(parent, child, 'cannot be empty')
25
- else
26
- if element['label'].blank?
27
- add_error(child, 'label', 'is required')
28
- end
29
- end
30
- items(element['child_classifications'], true) if element.has_key?('child_classifications')
31
- end
32
- else
33
- add_error(parent, child, 'must be a non-empty array')
34
- end
35
- end
36
- end
37
- end
38
-
@@ -1,150 +0,0 @@
1
- module Fulcrum
2
- class FormValidator < BaseValidator
3
-
4
- TYPES = %w(
5
- TextField
6
- ChoiceField
7
- ClassificationField
8
- PhotoField
9
- DateTimeField
10
- Section
11
- )
12
-
13
- def form_elements
14
- data['form']['elements']
15
- end
16
-
17
- def form_name
18
- data['form']['name']
19
- end
20
-
21
- def validate!
22
- @items = {}
23
- if data[:form]
24
- if form_elements && !form_elements.empty?
25
- add_error('form', 'name', 'cannot be blank') if data[:form][:name].blank?
26
- fields(form_elements)
27
- conditionals(form_elements)
28
- else
29
- add_error('form', 'elements', 'must be a non-empty array')
30
- end
31
- else
32
- @errors['form'] = ['must exist and not be empty']
33
- end
34
- return valid?
35
- end
36
-
37
- def fields(elements)
38
- if elements.kind_of?(Array) && !elements.empty?
39
- elements.each { |element| field(element) }
40
- else
41
- add_error('form', 'elements', 'must be a non-empty array')
42
- end
43
- end
44
-
45
- def field(element)
46
- if element.blank?
47
- add_error('elements', 'element', 'must not be empty')
48
- else
49
- if !element[:key]
50
- add_error('element', 'key', 'must exist and not be nil')
51
- return false
52
- end
53
-
54
- if @items.include?(element[:key])
55
- add_error(element[:key], :key, 'must be unique')
56
- return false
57
- end
58
-
59
- key = element[:key]
60
- @items[key] = element[:type]
61
-
62
- add_error(key, 'label', 'is required') if element[:label].blank?
63
- add_error(key, 'data_name', 'is required') if element[:data_name].blank?
64
- add_error(key, 'type', 'is not one of the valid types') unless TYPES.include?(element[:type])
65
-
66
- %w(disabled hidden required).each do |attrib|
67
- add_error(key, attrib, 'must be true or false') unless [true, false].include?(element[attrib])
68
- end
69
-
70
- case element[:type]
71
-
72
- when 'ClassificationField'
73
- if element[:classification_set_id]
74
- add_error(key, 'classification_set_id', 'is required') if element[:classification_set_id].blank?
75
- end
76
-
77
- when 'Section'
78
- if element['elements'].is_a?(Array)
79
- if element['elements'].any?
80
- fields(element['elements'])
81
- else
82
- add_error(key, 'elements', 'must contain additional elements')
83
- end
84
- else
85
- add_error(key, 'elements', 'must be an array object')
86
- end
87
-
88
- when 'ChoiceField'
89
- if element['choice_list_id']
90
- add_error(key, 'choice_list_id', 'is required') if element[:choice_list_id].blank?
91
- else
92
- if element['choices'].is_a?(Array) && !element['choices'].blank?
93
- element['choices'].each do |choice|
94
- unless choice.has_key?('label') && choice['label'].present?
95
- add_error('choices', 'label', 'contains an invalid label')
96
- end
97
- end
98
- else
99
- add_error(key, 'choices', 'must be a non-empty array')
100
- end
101
- end
102
- end
103
- end
104
- end
105
-
106
- def conditionals(elements)
107
- elements.each { |element| conditional(element) }
108
- end
109
-
110
- def conditional(element)
111
-
112
- operators = case element[:type]
113
- when 'ChoiceField', 'ClassificationField'
114
- %w(equal_to not_equal_to is_empty is_not_empty)
115
- else
116
- %w(equal_to not_equal_to contains starts_with greater_than less_than is_empty is_not_empty)
117
- end
118
-
119
- %w(required_conditions visible_conditions).each do |field|
120
-
121
- if type = element["#{field}_type"]
122
- add_error(key, "#{field}_type", 'is not valid') unless %(any all).include?(type)
123
- end
124
-
125
- if element[field]
126
- if element[field].is_a?(Array)
127
- element[field].each do |condition|
128
-
129
- if key = condition[:field_key]
130
- add_error(key, field, "key #{key} does not exist on the form") unless @items.keys.include?(key)
131
- add_error(key, field, "operator for #{key} is invalid") unless operators.include?(condition[:operator])
132
-
133
- if %w(is_empty is_not_empty).include?(condition[:operator]) && condition[:value].present?
134
- add_error(key, field, 'value cannot be blank')
135
- end
136
- else
137
- add_error(key, field, 'field key must exist for condition')
138
- end
139
-
140
- end
141
- else
142
- add_error(key, field, 'must be an array object')
143
- end
144
- end
145
- end
146
-
147
- conditionals(element[:elements]) if element[:type] == 'Section'
148
- end
149
- end
150
- end