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
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ include Support::ResourceExamples
4
+
5
+ describe Fulcrum::Layer do
6
+ include_context 'with client'
7
+ include_context 'with resource'
8
+
9
+ let(:resource) { client.layers }
10
+
11
+ include_examples 'list resource'
12
+ include_examples 'find resource'
13
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ include Support::ResourceExamples
4
+
5
+ describe Fulcrum::Membership do
6
+ include_context 'with client'
7
+ include_context 'with resource'
8
+
9
+ let(:resource) { client.memberships }
10
+
11
+ include_examples 'list resource'
12
+ end
@@ -1,95 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Fulcrum::Photo 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 '#retrieve' do
14
- it 'should retrieve the specified photo' do
15
- photo_id = 'abc'
16
- stub_request(:get, "#{Fulcrum::Api.configuration.uri}/photos/#{photo_id}.jpg").to_return(:status => 200)
17
- Fulcrum::Photo.find('abc', format: 'jpg')
18
- Fulcrum::Photo.response.status.should eq(200)
19
- end
20
- end
21
-
22
- context '#create' do
23
- it 'should create a new photo and return status 201' do
24
- stub_request(:post, "#{Fulcrum::Api.configuration.uri}/photos.json").to_return(:status => 201)
25
- pic = File.join(File.dirname(__FILE__), '..', 'data', 'test.jpg')
26
- Fulcrum::Photo.create(pic, 'image/*', 'abc', '')
27
- Fulcrum::Photo.response.status.should eq(201)
28
- end
29
- end
3
+ include Support::ResourceExamples
30
4
 
31
- context '#thumbnail' do
32
- it 'should retrieve the photo thumbnail and return status 200' do
33
- photo_id = 'abc'
34
- stub_request(:get, "#{Fulcrum::Api.configuration.uri}/photos/#{photo_id}/thumbnail.jpg").to_return(:status => 200)
35
- r = Fulcrum::Photo.thumbnail(photo_id, format: 'jpg')
36
- Fulcrum::Photo.response.status.should eq(200)
37
- end
38
- end
39
-
40
- context '#delete' do
41
- it 'should delete the photo and return status 200' do
42
- photo_id = 'abc'
43
- stub_request(:delete, "#{Fulcrum::Api.configuration.uri}/photos/#{photo_id}.json").to_return(:status => 204, :body => '{"photo":{}}')
44
- r = Fulcrum::Photo.delete(photo_id)
45
- Fulcrum::Photo.response.status.should eq(204)
46
- r = JSON.parse(r)
47
- r.keys.should include('photo')
48
- r['photo'].should be_a(Hash)
49
- end
50
- end
51
- end
52
-
53
- describe 'unsuccessful requests' do
54
- context '#retrieve' do
55
- it 'should receive 404' do
56
- photo_id = 'abc'
57
- stub_request(:get, "#{Fulcrum::Api.configuration.uri}/photos/#{photo_id}.jpg").to_return(:status => 404)
58
- p = Fulcrum::Photo.find(photo_id, format: 'jpg')
59
- p.keys.should include(:error)
60
- p[:error][:status].should eq(404)
61
- end
62
- end
5
+ describe Fulcrum::Photo do
6
+ let(:test_file) { './spec/data/test.jpg' }
63
7
 
64
- context '#create' do
65
- it 'should receive a 422 response' do
66
- stub_request(:post, "#{Fulcrum::Api.configuration.uri}/photos.json").to_return(:status => 422)
67
- pic = File.join(File.dirname(__FILE__), '..', 'data', 'test.jpg')
68
- p = Fulcrum::Photo.create(pic, 'image/*', 'abc', '')
69
- p.keys.should include(:error)
70
- p[:error][:status].should eq(422)
71
- end
72
- end
8
+ include_context 'with client'
9
+ include_context 'with media resource'
73
10
 
74
- context '#thumbnail' do
75
- it 'should receive a 422 response' do
76
- photo_id = 'abc'
77
- stub_request(:get, "#{Fulcrum::Api.configuration.uri}/photos/#{photo_id}/thumbnail.jpg").to_return(:status => 404)
78
- p = Fulcrum::Photo.thumbnail(photo_id, format: 'jpg')
79
- p.keys.should include(:error)
80
- p[:error][:status].should eq(404)
81
- end
82
- end
11
+ let(:resource) { client.photos }
83
12
 
84
- context '#delete' do
85
- it 'should receive a 404 response' do
86
- photo_id = 'abc'
87
- stub_request(:delete, "#{Fulcrum::Api.configuration.uri}/photos/#{photo_id}.json").to_return(:status => 404, :body => { :message => "error message"})
88
- p = Fulcrum::Photo.delete(photo_id)
89
- p.keys.should include(:error)
90
- p[:error][:status].should eq(404)
91
- p[:error][:message].should eq({ :message => "error message" })
92
- end
93
- end
94
- end
13
+ include_examples 'list resource'
14
+ include_examples 'find resource'
15
+ include_examples 'create resource'
95
16
  end
@@ -1,29 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Fulcrum::Project do
3
+ include Support::ResourceExamples
4
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
5
+ describe Fulcrum::Project do
6
+ include_context 'with client'
7
+ include_context 'with resource'
11
8
 
12
- describe 'successful requests' do
13
- context '#all' do
14
- it 'should retrieve all projects' do
15
- stub_request(:get, "#{Fulcrum::Api.configuration.uri}/projects.json").to_return(:status => 200, :body => '{"current_page":1,"total_pages":1,"total_count":1,"per_page":50,"projects":[]}')
16
- projects = Fulcrum::Project.all
17
- Fulcrum::Project.response.status.should eq(200)
18
- projects = JSON.parse(projects)
19
- projects.keys.should include('current_page')
20
- projects.keys.should include('total_pages')
21
- projects.keys.should include('total_count')
22
- projects.keys.should include('per_page')
23
- projects.keys.should include('projects')
24
- projects['projects'].should be_a(Array)
25
- end
26
- end
27
- end
9
+ let(:resource) { client.projects }
28
10
 
11
+ include_examples 'list resource'
12
+ include_examples 'find resource'
29
13
  end
@@ -1,121 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Fulcrum::Record 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 records' do
15
- stub_request(:get, "#{Fulcrum::Api.configuration.uri}/records.json").to_return(:status => 200, :body => '{"current_page":1,"total_pages":1,"total_count":1,"per_page":50,"records":[]}')
16
- records = Fulcrum::Record.all
17
- Fulcrum::Record.response.status.should eq(200)
18
- records = JSON.parse(records)
19
- records.keys.should include('current_page')
20
- records.keys.should include('total_pages')
21
- records.keys.should include('total_count')
22
- records.keys.should include('per_page')
23
- records.keys.should include('records')
24
- records['records'].should be_a(Array)
25
- end
26
- end
27
-
28
- context '#retrieve' do
29
- it 'should retrieve the specified record' do
30
- record_id = 'abc'
31
- stub_request(:get, "#{Fulcrum::Api.configuration.uri}/records/#{record_id}.json").to_return(:status => 200, :body => '{"record":{}}')
32
- r = Fulcrum::Record.find('abc')
33
- Fulcrum::Record.response.status.should eq(200)
34
- r = JSON.parse(r)
35
- r.keys.should include('record')
36
- r['record'].should be_a(Hash)
37
- end
38
- end
39
-
40
- context '#create' do
41
- it 'should create a new record and return status 201' do
42
- stub_request(:post, "#{Fulcrum::Api.configuration.uri}/records.json").to_return(:status => 201, :body => '{"record":{}}')
43
- Fulcrum::RecordValidator.any_instance.stub(:validate!).and_return(true)
44
- r = Fulcrum::Record.create({})
45
- Fulcrum::Record.response.status.should eq(201)
46
- r = JSON.parse(r)
47
- r.keys.should include('record')
48
- r['record'].should be_a(Hash)
49
- end
50
- end
3
+ include Support::ResourceExamples
51
4
 
52
- context '#update' do
53
- it 'should update the record and return status 200' do
54
- record_id = 'abc'
55
- stub_request(:put, "#{Fulcrum::Api.configuration.uri}/records/#{record_id}.json").to_return(:status => 200, :body => '{"record":{}}')
56
- Fulcrum::RecordValidator.any_instance.stub(:validate!).and_return(true)
57
- r = Fulcrum::Record.update(record_id, {})
58
- Fulcrum::Record.response.status.should eq(200)
59
- r = JSON.parse(r)
60
- r.keys.should include('record')
61
- r['record'].should be_a(Hash)
62
- end
63
- end
64
-
65
- context '#delete' do
66
- it 'should delete the record and return status 200' do
67
- record_id = 'abc'
68
- stub_request(:delete, "#{Fulcrum::Api.configuration.uri}/records/#{record_id}.json").to_return(:status => 204, :body => '{"record":{}}')
69
- r = Fulcrum::Record.delete(record_id)
70
- Fulcrum::Record.response.status.should eq(204)
71
- r = JSON.parse(r)
72
- r.keys.should include('record')
73
- r['record'].should be_a(Hash)
74
- end
75
- end
76
- end
77
-
78
- describe 'unsuccessful requests' do
79
- context '#retrieve' do
80
- it 'should receive 404' do
81
- record_id = 'abc'
82
- stub_request(:get, "#{Fulcrum::Api.configuration.uri}/records/#{record_id}.json").to_return(:status => 404)
83
- r = Fulcrum::Record.find(record_id)
84
- r.keys.should include(:error)
85
- r[:error][:status].should eq(404)
86
- end
87
- end
88
-
89
- context '#create' do
90
- it 'should receive a 422 response' do
91
- stub_request(:post, "#{Fulcrum::Api.configuration.uri}/records.json").to_return(:status => 422)
92
- Fulcrum::RecordValidator.any_instance.stub(:validate!).and_return(true)
93
- r = Fulcrum::Record.create({})
94
- r.keys.should include(:error)
95
- r[:error][:status].should eq(422)
96
- end
97
- end
5
+ describe Fulcrum::Record do
6
+ include_context 'with client'
7
+ include_context 'with resource'
98
8
 
99
- context '#update' do
100
- it 'should receive a 422 response' do
101
- record_id = 'abc'
102
- stub_request(:put, "#{Fulcrum::Api.configuration.uri}/records/#{record_id}.json").to_return(:status => 422)
103
- Fulcrum::RecordValidator.any_instance.stub(:validate!).and_return(true)
104
- r = Fulcrum::Record.update(record_id, {})
105
- r.keys.should include(:error)
106
- r[:error][:status].should eq(422)
107
- end
108
- end
9
+ let(:resource) { client.records }
109
10
 
110
- context '#delete' do
111
- it 'should receive a 404 response' do
112
- record_id = 'abc'
113
- stub_request(:delete, "#{Fulcrum::Api.configuration.uri}/records/#{record_id}.json").to_return(:status => 404, :body => { :message => "error message"})
114
- r = Fulcrum::Record.delete(record_id)
115
- r.keys.should include(:error)
116
- r[:error][:status].should eq(404)
117
- r[:error][:message].should eq({ :message => "error message" })
118
- end
119
- end
120
- end
11
+ include_examples 'list resource'
12
+ include_examples 'find resource'
13
+ include_examples 'create resource'
14
+ include_examples 'update resource'
15
+ include_examples 'delete resource'
121
16
  end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ include Support::ResourceExamples
4
+
5
+ describe Fulcrum::Signature do
6
+ let(:test_file) { './spec/data/test.png' }
7
+
8
+ include_context 'with client'
9
+ include_context 'with media resource'
10
+
11
+ let(:resource) { client.signatures }
12
+
13
+ include_examples 'list resource'
14
+ include_examples 'find resource'
15
+ include_examples 'create resource'
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ include Support::ResourceExamples
4
+
5
+ describe Fulcrum::Video do
6
+ let(:test_file) { './spec/data/test.mp4' }
7
+
8
+ include_context 'with client'
9
+ include_context 'with media resource'
10
+
11
+ let(:resource) { client.videos }
12
+
13
+ include_examples 'list resource'
14
+ include_examples 'find resource'
15
+ include_examples 'create resource'
16
+ end
@@ -0,0 +1,147 @@
1
+ require 'spec_helper'
2
+
3
+ include Support::ClientHelper
4
+
5
+ module Support
6
+ module ResourceExamples
7
+ shared_context 'with resource' do
8
+ let(:resource_object) { {} }
9
+ let(:create_parameters) { [ resource_object ] }
10
+ end
11
+
12
+ shared_context 'with media resource' do
13
+ let(:resource_object) { { id: SecureRandom.uuid } }
14
+ let(:create_parameters) { [ File.open(test_file), nil, { access_key: resource_id } ] }
15
+ end
16
+
17
+ shared_context 'with resource parameters' do
18
+ let(:resource_id) do
19
+ 'abc'
20
+ end
21
+
22
+ let(:resource_name) do
23
+ resource.resource_name
24
+ end
25
+
26
+ let(:resources_name) do
27
+ resource.resources_name
28
+ end
29
+
30
+ let(:collection_url) do
31
+ "#{client.url}/#{resource.collection}?per_page=#{resource.default_list_params[:per_page]}"
32
+ end
33
+
34
+ let(:member_url) do
35
+ "#{client.url}/#{resource.member(resource_id)}"
36
+ end
37
+
38
+ let(:show_response) do
39
+ data = {}
40
+ data[resource_name] = resource_object
41
+ data.as_json
42
+ end
43
+ end
44
+
45
+ shared_examples 'list resource' do
46
+ include_context 'with client'
47
+ include_context 'with resource parameters'
48
+
49
+ let(:pagination) do
50
+ { current_page: 1,
51
+ total_pages: 1,
52
+ total_count: 1,
53
+ per_page: 50 }
54
+ end
55
+
56
+ let(:list_response) do
57
+ data = pagination
58
+ data[resource.resources_name.to_sym] = []
59
+ data.as_json
60
+ end
61
+
62
+ it 'should list all resources' do
63
+ stub_request(:get, collection_url)
64
+ .to_return(status: 200, body: list_response)
65
+
66
+ page = resource.all
67
+
68
+ client.response.status.should eq(200)
69
+
70
+ page.should respond_to(:current_page)
71
+ page.should respond_to(:total_pages)
72
+ page.should respond_to(:total_count)
73
+ page.should respond_to(:per_page)
74
+
75
+ page.objects.should be_a(Array)
76
+ end
77
+ end
78
+
79
+ shared_examples 'find resource' do
80
+ include_context 'with client'
81
+ include_context 'with resource parameters'
82
+
83
+ it 'should find a resource' do
84
+ stub_request(:get, member_url)
85
+ .to_return(status: 200, body: show_response)
86
+
87
+ object = resource.find(resource_id)
88
+
89
+ client.response.status.should eq(200)
90
+
91
+ object.should be_a(Hash)
92
+ end
93
+ end
94
+
95
+ shared_examples 'create resource' do
96
+ include_context 'with client'
97
+ include_context 'with resource parameters'
98
+
99
+ let(:create_url) do
100
+ "#{client.url}/#{resource.create_action}"
101
+ end
102
+
103
+ it 'should create a new resource' do
104
+ stub_request(:post, create_url)
105
+ .to_return(status: 201, body: show_response)
106
+
107
+ object = resource.create(*create_parameters)
108
+
109
+ client.response.status.should eq(201)
110
+
111
+ object.should be_a(Hash)
112
+ end
113
+ end
114
+
115
+ shared_examples 'update resource' do
116
+ include_context 'with client'
117
+ include_context 'with resource parameters'
118
+
119
+ it 'should update a resource' do
120
+ stub_request(:put, member_url)
121
+ .to_return(status: 200, body: show_response)
122
+
123
+ object = resource.update(resource_id, resource_object)
124
+
125
+ client.response.status.should eq(200)
126
+
127
+ object.should be_a(Hash)
128
+ end
129
+ end
130
+
131
+ shared_examples 'delete resource' do
132
+ include_context 'with client'
133
+ include_context 'with resource parameters'
134
+
135
+ it 'should delete a resource' do
136
+ stub_request(:delete, member_url)
137
+ .to_return(status: 204, body: show_response)
138
+
139
+ object = resource.delete(resource_id)
140
+
141
+ client.response.status.should eq(204)
142
+
143
+ object.should be_a(Hash)
144
+ end
145
+ end
146
+ end
147
+ end