fulcrum 0.1.6 → 0.2.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.
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
@@ -1,18 +0,0 @@
1
- module Fulcrum
2
- class RecordValidator < BaseValidator
3
- def validate!
4
- if data['record'].kind_of?(Hash) && !data['record'].empty?
5
- add_error('record', 'form_id', 'cannot be blank') if data['record']['form_id'].blank?
6
- if data['record']['latitude'].to_f == 0.0 || data['record']['longitude'] == 0.0
7
- add_error('record', 'coordinates', 'must be in WGS84 format')
8
- end
9
- if !data['record']['form_values'].kind_of?(Hash) || data['record']['form_values'].blank?
10
- add_error('record', 'form_values', 'must be a non-empty hash')
11
- end
12
- else
13
- @errors['record'] = ['must be a non-empty hash']
14
- end
15
- return valid?
16
- end
17
- end
18
- end
@@ -1,175 +0,0 @@
1
- {
2
- "form": {
3
- "name": "Park Maintinence",
4
- "description": "Form for inspection of park's state of maintenance.",
5
- "created_at": "2012-04-27T10:48:31-04:00",
6
- "updated_at": "2012-04-27T10:58:39-04:00",
7
- "elements": [
8
- {
9
- "disabled":false,
10
- "hidden":false,
11
- "key":"b8fbca33-cad6-1eb5-b4ec-d78cf8aa9323",
12
- "type":"Section",
13
- "data_name":"park_report",
14
- "required":false,
15
- "label":"Park Report",
16
- "elements":[
17
- {
18
- "disabled":false,
19
- "hidden":false,
20
- "multiple":false,
21
- "allow_other":true,
22
- "key":"42277b35-92a0-2fe5-15df-baf4a2c11d69",
23
- "type":"ChoiceField",
24
- "data_name":"amenity_type",
25
- "required":false,
26
- "label":"Amenity Type",
27
- "choices":[
28
- {
29
- "value":"Boardwalk",
30
- "label":"Boardwalk"
31
- },
32
- {
33
- "value":"Pavilion",
34
- "label":"Pavilion"
35
- },
36
- {
37
- "value":"Bench",
38
- "label":"Bench"
39
- },
40
- {
41
- "value":"Path",
42
- "label":"Path"
43
- },
44
- {
45
- "value":"Playground Equipment",
46
- "label":"Playground Equipment"
47
- },
48
- {
49
- "value":"Land",
50
- "label":"Land"
51
- },
52
- {
53
- "value":"Restroom",
54
- "label":"Restroom"
55
- },
56
- {
57
- "value":"Athletic Field",
58
- "label":"Athletic Field"
59
- },
60
- {
61
- "value":"Boat Ramp",
62
- "label":"Boat Ramp"
63
- },
64
- {
65
- "value":"Picnic Table",
66
- "label":"Picnic Table"
67
- },
68
- {
69
- "value":"Dog Park",
70
- "label":"Dog Park"
71
- }
72
- ]
73
- },
74
- {
75
- "disabled":false,
76
- "hidden":false,
77
- "multiple":false,
78
- "allow_other":true,
79
- "key":"dec7d431-981e-55fe-ce27-fa0ce588b7b3",
80
- "type":"ChoiceField",
81
- "data_name":"type_of_problem",
82
- "required":false,
83
- "label":"Type of Problem",
84
- "choices":[
85
- {
86
- "value":"Vandalism",
87
- "label":"Vandalism"
88
- },
89
- {
90
- "value":"Invasive Plant Species",
91
- "label":"Invasive Plant Species"
92
- },
93
- {
94
- "value":"Pests",
95
- "label":"Pests"
96
- },
97
- {
98
- "value":"Damage",
99
- "label":"Damage"
100
- },
101
- {
102
- "value":"None",
103
- "label":"None"
104
- }
105
- ]
106
- },
107
- {
108
- "disabled":false,
109
- "hidden":false,
110
- "key":"bbd86b27-4792-1ba3-6bf3-65b7bb5ee124",
111
- "type":"TextField",
112
- "data_name":"problem_notes",
113
- "required":false,
114
- "label":"Problem Notes"
115
- },
116
- {
117
- "disabled":false,
118
- "hidden":false,
119
- "multiple":false,
120
- "allow_other":true,
121
- "key":"36d58746-2b5c-a545-3009-5744de326e69",
122
- "type":"ChoiceField",
123
- "data_name":"urgency_",
124
- "required":false,
125
- "label":"Urgency ",
126
- "choices":[
127
- {
128
- "value":"High",
129
- "label":"High"
130
- },
131
- {
132
- "value":"Medium",
133
- "label":"Medium"
134
- },
135
- {
136
- "value":"Low",
137
- "label":"Low"
138
- },
139
- {
140
- "value":"None",
141
- "label":"None"
142
- }
143
- ]
144
- },
145
- {
146
- "disabled":false,
147
- "hidden":false,
148
- "key":"4194cc93-99ff-fb2c-ec1f-ad4e394e6731",
149
- "type":"TextField",
150
- "data_name":"name_of_park",
151
- "required":false,
152
- "label":"Name of Park"
153
- },
154
- {
155
- "disabled":false,
156
- "hidden":false,
157
- "key":"21f0b6d5-4154-030e-d552-13819dfb3a0a",
158
- "type":"PhotoField",
159
- "required":false,
160
- "label":"Photos"
161
- }
162
- ]
163
- },
164
- {
165
- "disabled":false,
166
- "hidden":false,
167
- "key":"1797370a-06c3-a263-6c8f-17dcf7186b11",
168
- "type":"DateTimeField",
169
- "data_name":"date_of_report",
170
- "required":false,
171
- "label":"Date of Report"
172
- }
173
- ]
174
- }
175
- }
data/spec/lib/api_spec.rb DELETED
@@ -1,42 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Fulcrum::Api do
4
- let(:default_uri) { 'https://api.fulcrumapp.com/api/v2' }
5
-
6
- let(:uri) { 'http://foo.bar/api/v2' }
7
- let(:key) { 'foobar' }
8
-
9
- it 'has a default uri' do
10
- Fulcrum::Api.configuration.uri.should eq(default_uri)
11
- end
12
-
13
- it 'is configured' do
14
- Fulcrum::Api.configure do |config|
15
- config.uri = uri
16
- config.key = key
17
- end
18
-
19
- Fulcrum::Api.configuration.uri.should eq(uri)
20
- Fulcrum::Api.configuration.key.should eq(key)
21
- end
22
-
23
- it 'gets the key' do
24
- user = "foo@bar.com"
25
- pass = "foobar"
26
- stub_request(:get, /.*\/users.json/).to_return(:status => 200, :body => '{ "user": { "api_token": "foobar" }}')
27
- Fulcrum::Api.get_key(user, pass).should eq('foobar')
28
- end
29
-
30
- specify '#parse_opts returns only expected opts' do
31
- params = Fulcrum::Api.parse_opts([:foo], { foo: 'bar', bar: 'foo'})
32
- params.should eq({ foo: 'bar' })
33
- end
34
-
35
- specify '#call should raise ArgumentError with invalid method' do
36
- expect { Fulcrum::Api.call(:foo) }.to raise_error(ArgumentError)
37
- end
38
-
39
- specify '#call should not raise ArgumentError with valid method' do
40
- expect { Fulcrum::Api.call(:get) }.to_not raise_error(ArgumentError)
41
- end
42
- end
@@ -1,52 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Fulcrum::Member do
4
-
5
- before(:all) do
6
- Fulcrum::Api.configure do |config|
7
- config.uri = 'http://foo.bar/api/v2'
8
- config.key = 'foobar'
9
- end
10
- end
11
-
12
- describe 'successful requests' do
13
- context '#all' do
14
- it 'should retrieve all members' do
15
- stub_request(:get, "#{Fulcrum::Api.configuration.uri}/members.json").to_return(:status => 200, :body => '{"current_page":1,"total_pages":1,"total_count":1,"per_page":50,"members":[]}')
16
- members = Fulcrum::Member.all
17
- Fulcrum::Member.response.status.should eq(200)
18
- members = JSON.parse(members)
19
- members.keys.should include('current_page')
20
- members.keys.should include('total_pages')
21
- members.keys.should include('total_count')
22
- members.keys.should include('per_page')
23
- members.keys.should include('members')
24
- members['members'].should be_a(Array)
25
- end
26
- end
27
-
28
- context '#retrieve' do
29
- it 'should retrieve the specified member' do
30
- member_id = 'abc'
31
- stub_request(:get, "#{Fulcrum::Api.configuration.uri}/members/#{member_id}.json").to_return(:status => 200, :body => '{"member":{}}')
32
- m = Fulcrum::Member.find('abc')
33
- Fulcrum::Member.response.status.should eq(200)
34
- m = JSON.parse(m)
35
- m.keys.should include('member')
36
- m['member'].should be_a(Hash)
37
- end
38
- end
39
- end
40
-
41
- describe 'unsuccessful requests' do
42
- context '#retrieve' do
43
- it 'should receive 404' do
44
- member_id = 'abc'
45
- stub_request(:get, "#{Fulcrum::Api.configuration.uri}/members/#{member_id}.json").to_return(:status => 404)
46
- m = Fulcrum::Member.find(member_id)
47
- m.keys.should include(:error)
48
- m[:error][:status].should eq(404)
49
- end
50
- end
51
- end
52
- end
@@ -1,73 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Fulcrum::ChoiceListValidator do
4
-
5
- describe '#validates!' do
6
- it 'should not be valid without a choice_list hash' do
7
- data = {}
8
- validator = Fulcrum::ChoiceListValidator.new(data)
9
- validator.should_not be_valid
10
- end
11
-
12
- it 'should not be valid if choice_list is not a hash' do
13
- data = { 'choice_list' => nil }
14
- validator = Fulcrum::ChoiceListValidator.new(data)
15
- validator.should_not be_valid
16
- end
17
-
18
- it 'should not be valid without an empty choice_list hash' do
19
- data = { 'choice_list' => {}}
20
- validator = Fulcrum::ChoiceListValidator.new(data)
21
- validator.should_not be_valid
22
- end
23
-
24
- it 'should not be valid without a name' do
25
- data = { 'choice_list' => { 'name' => '' } }
26
- validator = Fulcrum::ChoiceListValidator.new(data)
27
- validator.should_not be_valid
28
- validator.errors['choice_list']['name'].should_not be_blank
29
- end
30
-
31
- it 'should not be valid without any choices' do
32
- data = { 'choice_list' => { 'name' => 'foobar' } }
33
- validator = Fulcrum::ChoiceListValidator.new(data)
34
- validator.should_not be_valid
35
- validator.errors['choice_list']['choices'].should_not be_blank
36
- end
37
-
38
- it 'should not be valid with a non array choices element' do
39
- data = { 'choice_list' => { 'name' => 'foobar', 'choices'=> {} } }
40
- validator = Fulcrum::ChoiceListValidator.new(data)
41
- validator.should_not be_valid
42
- validator.errors['choice_list']['choices'].should_not be_blank
43
- end
44
-
45
- it 'should not be valid with an empty choices array' do
46
- data = { 'choice_list' => { 'name' => 'foobar', 'choices'=> [] } }
47
- validator = Fulcrum::ChoiceListValidator.new(data)
48
- validator.should_not be_valid
49
- validator.errors['choice_list']['choices'].should_not be_blank
50
- end
51
-
52
- it 'should not be valid with an empty choice' do
53
- data = { 'choice_list' => { 'name' => 'foobar', 'choices'=> [{}] } }
54
- validator = Fulcrum::ChoiceListValidator.new(data)
55
- validator.should_not be_valid
56
- validator.errors['choices']['choice'].should_not be_blank
57
- end
58
-
59
- it 'should not be valid with a choice that does not have label' do
60
- data = { 'choice_list' => { 'name' => 'foobar', 'choices'=> [{ 'foo' => 'bar' }] } }
61
- validator = Fulcrum::ChoiceListValidator.new(data)
62
- validator.should_not be_valid
63
- validator.errors['choice']['label'].should_not be_blank
64
- end
65
-
66
- it 'should be valid' do
67
- data = { 'choice_list' => { 'name' => 'foobar', 'choices'=> [{ 'label' => 'foo' }] } }
68
- validator = Fulcrum::ChoiceListValidator.new(data)
69
- validator.should be_valid
70
- validator.errors.should be_empty
71
- end
72
- end
73
- end
@@ -1,88 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Fulcrum::ClassificationSetValidator do
4
-
5
- describe '#validates!' do
6
- it 'should not be valid without a classification_set hash' do
7
- data = {}
8
- validator = Fulcrum::ClassificationSetValidator.new(data)
9
- validator.should_not be_valid
10
- end
11
-
12
- it 'should not be valid if classification_set is not a hash' do
13
- data = { 'classification_set' => nil }
14
- validator = Fulcrum::ClassificationSetValidator.new(data)
15
- validator.should_not be_valid
16
- end
17
-
18
- it 'should not be valid without an empty classification_set hash' do
19
- data = { 'classification_set' => {}}
20
- validator = Fulcrum::ClassificationSetValidator.new(data)
21
- validator.should_not be_valid
22
- end
23
-
24
- it 'should not be valid without a name' do
25
- data = { 'classification_set' => { 'name' => '' } }
26
- validator = Fulcrum::ClassificationSetValidator.new(data)
27
- validator.should_not be_valid
28
- validator.errors['classification_set']['name'].should_not be_blank
29
- end
30
-
31
- it 'should not be valid without any items' do
32
- data = { 'classification_set' => { 'name' => 'foobar' } }
33
- validator = Fulcrum::ClassificationSetValidator.new(data)
34
- validator.should_not be_valid
35
- validator.errors['classification_set']['items'].should_not be_blank
36
- end
37
-
38
- it 'should not be valid with a non array items element' do
39
- data = { 'classification_set' => { 'name' => 'foobar', 'items'=> {} } }
40
- validator = Fulcrum::ClassificationSetValidator.new(data)
41
- validator.should_not be_valid
42
- validator.errors['classification_set']['items'].should_not be_blank
43
- end
44
-
45
- it 'should not be valid with an empty items array' do
46
- data = { 'classification_set' => { 'name' => 'foobar', 'items'=> [] } }
47
- validator = Fulcrum::ClassificationSetValidator.new(data)
48
- validator.should_not be_valid
49
- validator.errors['classification_set']['items'].should_not be_blank
50
- end
51
-
52
- it 'should not be valid with an empty item' do
53
- data = { 'classification_set' => { 'name' => 'foobar', 'items'=> [{}] } }
54
- validator = Fulcrum::ClassificationSetValidator.new(data)
55
- validator.should_not be_valid
56
- validator.errors['items']['item'].should_not be_blank
57
- end
58
-
59
- it 'should not be valid with a item that does not have label' do
60
- data = { 'classification_set' => { 'name' => 'foobar', 'items'=> [{ 'foo' => 'bar' }] } }
61
- validator = Fulcrum::ClassificationSetValidator.new(data)
62
- validator.should_not be_valid
63
- validator.errors['item']['label'].should_not be_blank
64
- end
65
-
66
- it 'should be valid with a good classification set item' do
67
- data = { 'classification_set' => { 'name' => 'foobar', 'items'=> [{ 'label' => 'foo' }] } }
68
- validator = Fulcrum::ClassificationSetValidator.new(data)
69
- validator.should be_valid
70
- validator.errors.should be_empty
71
- end
72
-
73
- # child classifications
74
- it 'should not be valid if an item has an empty child classifications' do
75
- data = { 'classification_set' => { 'name' => 'foobar', 'items'=> [{ 'label' => 'bar', 'child_classifications' => [] }] } }
76
- validator = Fulcrum::ClassificationSetValidator.new(data)
77
- validator.should_not be_valid
78
- validator.errors['child_classification']['item'].should_not be_blank
79
- end
80
-
81
- it 'should be valid with good child classifications' do
82
- data = { 'classification_set' => { 'name' => 'foobar', 'items'=> [{ 'label' => 'bar', 'child_classifications' => [{ 'label' => 'foo'}] }] } }
83
- validator = Fulcrum::ClassificationSetValidator.new(data)
84
- validator.should be_valid
85
- validator.errors.should be_empty
86
- end
87
- end
88
- end