gather_content-api 1.0.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.
- 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
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe GatherContent::Api::Item, vcr: true do
|
|
4
|
+
let(:item_id) { '123456' }
|
|
5
|
+
let(:item) { GatherContent::Api::Item.new(item_id) }
|
|
6
|
+
|
|
7
|
+
describe '.new' do
|
|
8
|
+
subject { item }
|
|
9
|
+
|
|
10
|
+
context 'when item ID is passed in' do
|
|
11
|
+
it { is_expected.to be_a GatherContent::Api::Item }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context 'when item ID is not passed in' do
|
|
15
|
+
let(:item_id) { nil }
|
|
16
|
+
it 'should raise an ArgumentError' do
|
|
17
|
+
expect { subject }.to raise_error ArgumentError
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe '#fetch' do
|
|
23
|
+
subject { item.fetch }
|
|
24
|
+
it { is_expected.to be_a Hash }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe "[]" do
|
|
28
|
+
subject { item }
|
|
29
|
+
|
|
30
|
+
it "returns the data related to the supplied key" do
|
|
31
|
+
expect(subject["id"]).to eq(123456)
|
|
32
|
+
expect(subject["project_id"]).to eq(123456)
|
|
33
|
+
expect(subject["parent_id"]).to eq(0)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe "save" do
|
|
38
|
+
let(:config) { {} }
|
|
39
|
+
subject { item.save(config) }
|
|
40
|
+
|
|
41
|
+
context "successful" do
|
|
42
|
+
let(:config) {
|
|
43
|
+
[{
|
|
44
|
+
"label": "Content",
|
|
45
|
+
"name": "tab1",
|
|
46
|
+
"hidden": false,
|
|
47
|
+
"elements": [{
|
|
48
|
+
"type": "text",
|
|
49
|
+
"name": "el1",
|
|
50
|
+
"required": false,
|
|
51
|
+
"label": "Blog post",
|
|
52
|
+
"value": "Hello world",
|
|
53
|
+
"microcopy": "",
|
|
54
|
+
"limit_type": "words",
|
|
55
|
+
"limit": 1000,
|
|
56
|
+
"plain_text": false
|
|
57
|
+
}]
|
|
58
|
+
}]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
it "returns true" do
|
|
62
|
+
expect(subject).to eq(true)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
context "unsuccessful" do
|
|
67
|
+
it 'raises an RequestError' do
|
|
68
|
+
expect { subject }.to raise_error GatherContent::Error::RequestError
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'sets the RequestError status' do
|
|
72
|
+
begin
|
|
73
|
+
subject
|
|
74
|
+
rescue GatherContent::Error::RequestError => e
|
|
75
|
+
expect(e.status).to eq(400)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'parses the message' do
|
|
80
|
+
begin
|
|
81
|
+
subject
|
|
82
|
+
rescue GatherContent::Error::RequestError => e
|
|
83
|
+
expect(e.message).to eq("Invalid config field")
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe "apply_template" do
|
|
90
|
+
subject { item.apply_template(template_id) }
|
|
91
|
+
|
|
92
|
+
context "successful" do
|
|
93
|
+
let(:template_id) { 1085780 }
|
|
94
|
+
|
|
95
|
+
it "returns true" do
|
|
96
|
+
expect(subject).to eq(true)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
context "unsuccessful" do
|
|
101
|
+
let(:template_id) { 1085779 }
|
|
102
|
+
it 'raises an RequestError' do
|
|
103
|
+
expect { subject }.to raise_error GatherContent::Error::RequestError
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it 'sets the RequestError status' do
|
|
107
|
+
begin
|
|
108
|
+
subject
|
|
109
|
+
rescue GatherContent::Error::RequestError => e
|
|
110
|
+
expect(e.status).to eq(500)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it 'parses the message' do
|
|
115
|
+
begin
|
|
116
|
+
subject
|
|
117
|
+
rescue GatherContent::Error::RequestError => e
|
|
118
|
+
expect(e.message).to eq("unknown error")
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
describe "choose_status" do
|
|
125
|
+
subject { item.choose_status(status_id) }
|
|
126
|
+
|
|
127
|
+
context "successful" do
|
|
128
|
+
let(:status_id) { 991221 }
|
|
129
|
+
|
|
130
|
+
it "returns true" do
|
|
131
|
+
expect(subject).to eq(true)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
context "unsuccessful" do
|
|
136
|
+
let(:status_id) { 991219 }
|
|
137
|
+
it 'raises an RequestError' do
|
|
138
|
+
expect { subject }.to raise_error GatherContent::Error::RequestError
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it 'sets the RequestError status' do
|
|
142
|
+
begin
|
|
143
|
+
subject
|
|
144
|
+
rescue GatherContent::Error::RequestError => e
|
|
145
|
+
expect(e.status).to eq(500)
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it 'parses the message' do
|
|
150
|
+
begin
|
|
151
|
+
subject
|
|
152
|
+
rescue GatherContent::Error::RequestError => e
|
|
153
|
+
expect(e.message).to eq("unknown error")
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe GatherContent::Api::Items, vcr: true do
|
|
4
|
+
let(:project_id) { '123456' }
|
|
5
|
+
let(:items) { GatherContent::Api::Items.new(project_id) }
|
|
6
|
+
|
|
7
|
+
describe '.new' do
|
|
8
|
+
subject { items }
|
|
9
|
+
|
|
10
|
+
context 'when project ID is passed in' do
|
|
11
|
+
it { is_expected.to be_a GatherContent::Api::Items }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context 'when project ID is not passed in' do
|
|
15
|
+
let(:project_id) { nil }
|
|
16
|
+
it 'should raise an ArgumentError' do
|
|
17
|
+
expect { subject }.to raise_error ArgumentError
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe '#each' do
|
|
23
|
+
subject { items }
|
|
24
|
+
|
|
25
|
+
it { is_expected.to be_a Enumerable }
|
|
26
|
+
|
|
27
|
+
it 'should contain Item objects' do
|
|
28
|
+
subject.each do |item|
|
|
29
|
+
expect(item).to be_a GatherContent::Api::Item
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'should have memoized data' do
|
|
34
|
+
expect(subject.first["id"]).to eq(123456)
|
|
35
|
+
expect(subject.first["project_id"]).to eq(123456)
|
|
36
|
+
expect(subject.first["parent_id"]).to eq(0)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe "#create" do
|
|
41
|
+
let(:name) { "Test Item" }
|
|
42
|
+
let(:config) { nil }
|
|
43
|
+
|
|
44
|
+
subject { items.create({'name' => name, 'config' => config}) }
|
|
45
|
+
|
|
46
|
+
context 'with name' do
|
|
47
|
+
it "created an item" do
|
|
48
|
+
expect(subject).to be_a GatherContent::Api::Item
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "set the item id" do
|
|
52
|
+
expect(subject.item_id).to eq("6499285")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
context 'with no name' do
|
|
57
|
+
let(:name) { nil }
|
|
58
|
+
|
|
59
|
+
it 'should raise an ArgumentError' do
|
|
60
|
+
expect { subject }.to raise_error ArgumentError
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context 'with empty name' do
|
|
65
|
+
let(:name) { "" }
|
|
66
|
+
|
|
67
|
+
it 'should raise an ArgumentError' do
|
|
68
|
+
expect { subject }.to raise_error ArgumentError
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
context 'with config' do
|
|
73
|
+
let(:config) do
|
|
74
|
+
[{
|
|
75
|
+
"label": "Content",
|
|
76
|
+
"name": "tab1",
|
|
77
|
+
"hidden": false,
|
|
78
|
+
"elements": [{
|
|
79
|
+
"type": "text",
|
|
80
|
+
"name": "el1",
|
|
81
|
+
"required": false,
|
|
82
|
+
"label": "Blog post",
|
|
83
|
+
"value": "Hello world",
|
|
84
|
+
"microcopy": "",
|
|
85
|
+
"limit_type": "words",
|
|
86
|
+
"limit": 1000,
|
|
87
|
+
"plain_text": false
|
|
88
|
+
}]
|
|
89
|
+
}]
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "created an item" do
|
|
93
|
+
expect(subject).to be_a GatherContent::Api::Item
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "set the item id" do
|
|
97
|
+
expect(subject.item_id).to eq("6499285")
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "sets the content" do
|
|
101
|
+
expect(subject["config"]).to_not be_nil
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
context 'on non-202 response' do
|
|
106
|
+
it 'raises an RequestError' do
|
|
107
|
+
expect { subject }.to raise_error GatherContent::Error::RequestError
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it 'sets the RequestError message' do
|
|
111
|
+
begin
|
|
112
|
+
subject
|
|
113
|
+
rescue GatherContent::Error::RequestError => e
|
|
114
|
+
expect(e.message).to eq("")
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it 'sets the RequestError status' do
|
|
119
|
+
begin
|
|
120
|
+
subject
|
|
121
|
+
rescue GatherContent::Error::RequestError => e
|
|
122
|
+
expect(e.status).to eq(200)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe GatherContent::Api::Me, vcr: true do
|
|
4
|
+
let(:me) { GatherContent::Api::Me.new }
|
|
5
|
+
|
|
6
|
+
describe '.new' do
|
|
7
|
+
subject { me }
|
|
8
|
+
|
|
9
|
+
it { is_expected.to be_a GatherContent::Api::Me }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe '#fetch' do
|
|
13
|
+
subject { me.fetch }
|
|
14
|
+
it { is_expected.to be_a Hash }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe "[]" do
|
|
18
|
+
subject { me }
|
|
19
|
+
|
|
20
|
+
it "returns the data related to the supplied key" do
|
|
21
|
+
expect(subject["email"]).to eq("andrew@gathercontent.com")
|
|
22
|
+
expect(subject["first_name"]).to eq("Andrew")
|
|
23
|
+
expect(subject["last_name"]).to eq("Cairns")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe GatherContent::Api::Project, vcr: true do
|
|
4
|
+
let(:project_id) { 123456 }
|
|
5
|
+
let(:project) { GatherContent::Api::Project.new(project_id) }
|
|
6
|
+
|
|
7
|
+
describe '.new' do
|
|
8
|
+
subject { project }
|
|
9
|
+
|
|
10
|
+
it { is_expected.to be_a GatherContent::Api::Project }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '#get' do
|
|
14
|
+
subject { project.project_id }
|
|
15
|
+
it { is_expected.to eql project_id }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe '#fetch' do
|
|
19
|
+
subject { project.fetch }
|
|
20
|
+
it { is_expected.to be_a Hash }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "[]" do
|
|
24
|
+
subject { project }
|
|
25
|
+
|
|
26
|
+
it "returns the data related to the supplied key" do
|
|
27
|
+
expect(subject["id"]).to eq(123456)
|
|
28
|
+
expect(subject["name"]).to eq("Example Project")
|
|
29
|
+
expect(subject["account_id"]).to eq(123456)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe GatherContent::Api::Projects, vcr: true do
|
|
4
|
+
let(:account_id) { 123456 }
|
|
5
|
+
let(:projects) { GatherContent::Api::Projects.new(account_id) }
|
|
6
|
+
|
|
7
|
+
describe '#each' do
|
|
8
|
+
subject { projects }
|
|
9
|
+
it { is_expected.to be_a Enumerable }
|
|
10
|
+
|
|
11
|
+
it 'should contain Project objects' do
|
|
12
|
+
projects.each do |project|
|
|
13
|
+
expect(project).to be_a GatherContent::Api::Project
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "#create" do
|
|
19
|
+
let(:name) { "Test Project" }
|
|
20
|
+
let(:type) { "website-build" }
|
|
21
|
+
|
|
22
|
+
subject { projects.create({'name' => name, 'type' => type}) }
|
|
23
|
+
|
|
24
|
+
context 'with name and valid type' do
|
|
25
|
+
it "created a project" do
|
|
26
|
+
expect(subject).to be_a GatherContent::Api::Project
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "set the project id" do
|
|
30
|
+
expect(subject.project_id).to eq("161823")
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context 'with no name' do
|
|
35
|
+
let(:name) { nil }
|
|
36
|
+
|
|
37
|
+
it 'should raise an ArgumentError' do
|
|
38
|
+
expect { subject }.to raise_error ArgumentError
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
context 'with empty name' do
|
|
43
|
+
let(:name) { "" }
|
|
44
|
+
|
|
45
|
+
it 'should raise an ArgumentError' do
|
|
46
|
+
expect { subject }.to raise_error ArgumentError
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context 'with no type' do
|
|
51
|
+
let(:type) { nil }
|
|
52
|
+
|
|
53
|
+
it "created a project" do
|
|
54
|
+
expect(subject).to be_a GatherContent::Api::Project
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context 'with empty type' do
|
|
59
|
+
let(:type) { "" }
|
|
60
|
+
|
|
61
|
+
it "created a project" do
|
|
62
|
+
expect(subject).to be_a GatherContent::Api::Project
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
context 'with invalid type' do
|
|
67
|
+
let(:type) { "invalid" }
|
|
68
|
+
|
|
69
|
+
it 'should raise an ArgumentError' do
|
|
70
|
+
expect { subject }.to raise_error ArgumentError
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
context 'on non-202 response' do
|
|
75
|
+
it 'raises an RequestError' do
|
|
76
|
+
expect { subject }.to raise_error GatherContent::Error::RequestError
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'sets the RequestError message' do
|
|
80
|
+
begin
|
|
81
|
+
subject
|
|
82
|
+
rescue GatherContent::Error::RequestError => e
|
|
83
|
+
expect(e.message).to eq("Account not found")
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'sets the RequestError status' do
|
|
88
|
+
begin
|
|
89
|
+
subject
|
|
90
|
+
rescue GatherContent::Error::RequestError => e
|
|
91
|
+
expect(e.status).to eq(200)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe GatherContent::Api::Status, vcr: true do
|
|
4
|
+
let(:project_id) { 123456 }
|
|
5
|
+
let(:status_id) { 123456 }
|
|
6
|
+
let(:status) { GatherContent::Api::Status.new(project_id, status_id) }
|
|
7
|
+
|
|
8
|
+
describe '.new' do
|
|
9
|
+
subject { status }
|
|
10
|
+
|
|
11
|
+
context 'when project id and status is is passed in' do
|
|
12
|
+
it { is_expected.to be_a GatherContent::Api::Status }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
context 'when project id is not passed in' do
|
|
16
|
+
let(:project_id) { nil }
|
|
17
|
+
it 'should raise an ArgumentError' do
|
|
18
|
+
expect { subject }.to raise_error ArgumentError
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context 'when status id is not passed in' do
|
|
23
|
+
let(:status_id) { nil }
|
|
24
|
+
it 'should raise an ArgumentError' do
|
|
25
|
+
expect { subject }.to raise_error ArgumentError
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe '#fetch' do
|
|
31
|
+
subject { status.fetch }
|
|
32
|
+
it { is_expected.to be_a Hash }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe "[]" do
|
|
36
|
+
subject { status }
|
|
37
|
+
|
|
38
|
+
it "returns the data related to the supplied key" do
|
|
39
|
+
expect(subject["id"]).to eq("123456")
|
|
40
|
+
expect(subject["is_default"]).to eq(true)
|
|
41
|
+
expect(subject["position"]).to eq("1")
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe GatherContent::Api::Statuses, vcr: true do
|
|
4
|
+
let(:project_id) { 123456 }
|
|
5
|
+
let(:statuses) { GatherContent::Api::Statuses.new(project_id) }
|
|
6
|
+
|
|
7
|
+
describe '.new' do
|
|
8
|
+
subject { statuses }
|
|
9
|
+
|
|
10
|
+
context 'when project id is passed in' do
|
|
11
|
+
it { is_expected.to be_a GatherContent::Api::Statuses }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context 'when project id is not passed in' do
|
|
15
|
+
let(:project_id) { nil }
|
|
16
|
+
it 'should raise an ArgumentError' do
|
|
17
|
+
expect { subject }.to raise_error ArgumentError
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe '#each' do
|
|
23
|
+
subject { statuses }
|
|
24
|
+
|
|
25
|
+
it { is_expected.to be_a Enumerable }
|
|
26
|
+
|
|
27
|
+
it 'should contain Status objects' do
|
|
28
|
+
subject.each do |status|
|
|
29
|
+
expect(status).to be_a GatherContent::Api::Status
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'should have memoized data' do
|
|
34
|
+
expect(subject.first["id"]).to eq("123456")
|
|
35
|
+
expect(subject.first["is_default"]).to eq(true)
|
|
36
|
+
expect(subject.first["position"]).to eq("1")
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe GatherContent::Api::Template, vcr: true do
|
|
4
|
+
let(:template_id) { '123456' }
|
|
5
|
+
let(:template) { GatherContent::Api::Template.new(template_id) }
|
|
6
|
+
|
|
7
|
+
describe '.new' do
|
|
8
|
+
subject { template }
|
|
9
|
+
|
|
10
|
+
context 'when template ID is passed in' do
|
|
11
|
+
it { is_expected.to be_a GatherContent::Api::Template }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context 'when template ID is not passed in' do
|
|
15
|
+
let(:template_id) { nil }
|
|
16
|
+
it 'should raise an ArgumentError' do
|
|
17
|
+
expect { subject }.to raise_error ArgumentError
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe '#fetch' do
|
|
23
|
+
subject { template.fetch }
|
|
24
|
+
it { is_expected.to be_a Hash }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe "[]" do
|
|
28
|
+
subject { template }
|
|
29
|
+
|
|
30
|
+
it "returns the data related to the supplied key" do
|
|
31
|
+
expect(subject["id"]).to eq(123456)
|
|
32
|
+
expect(subject["project_id"]).to eq(123456)
|
|
33
|
+
expect(subject["name"]).to eq("Blog Theme")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe GatherContent::Api::Templates, vcr: true do
|
|
4
|
+
let(:project_id) { 123456 }
|
|
5
|
+
let(:templates) { GatherContent::Api::Templates.new(project_id) }
|
|
6
|
+
|
|
7
|
+
describe '#each' do
|
|
8
|
+
subject { templates }
|
|
9
|
+
it { is_expected.to be_a Enumerable }
|
|
10
|
+
|
|
11
|
+
it 'should contain Template objects' do
|
|
12
|
+
templates.each do |template|
|
|
13
|
+
expect(template).to be_a GatherContent::Api::Template
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'should have memoized data' do
|
|
18
|
+
expect(subject.first["id"]).to eq(123456)
|
|
19
|
+
expect(subject.first["project_id"]).to eq(123456)
|
|
20
|
+
expect(subject.first["name"]).to eq("Blog Theme")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'coveralls'
|
|
2
|
+
Coveralls.wear!
|
|
3
|
+
|
|
4
|
+
$: << "#{File.dirname(__FILE__)}/../lib"
|
|
5
|
+
Dir['#{File.dirname(__FILE__)}/support/**/*.rb'].each {|f| require f}
|
|
6
|
+
|
|
7
|
+
require 'pry'
|
|
8
|
+
require 'vcr'
|
|
9
|
+
require 'gather_content'
|
|
10
|
+
require 'climate_control'
|
|
11
|
+
# require 'figs'
|
|
12
|
+
# Figs.load()
|
|
13
|
+
|
|
14
|
+
VCR.configure do |c|
|
|
15
|
+
c.filter_sensitive_data('api-id') { GatherContent::Api::Config.instance.username }
|
|
16
|
+
c.filter_sensitive_data('api-key') { GatherContent::Api::Config.instance.api_key }
|
|
17
|
+
c.filter_sensitive_data('gather_content_api_host') { ENV['GATHER_CONTENT_API_HOST'] }
|
|
18
|
+
c.default_cassette_options = { record: :new_episodes, allow_playback_repeats: true }
|
|
19
|
+
c.cassette_library_dir = 'spec/vcr_cassettes'
|
|
20
|
+
c.configure_rspec_metadata!
|
|
21
|
+
c.hook_into :webmock
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def with_modified_env(options, &block)
|
|
25
|
+
ClimateControl.modify(options, &block)
|
|
26
|
+
end
|
data/spec/vcr_cassettes/GatherContent_Api_Account/_/returns_the_data_related_to_the_supplied_key.yml
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: get
|
|
5
|
+
uri: https://api.gathercontent.com/accounts/123456
|
|
6
|
+
body:
|
|
7
|
+
encoding: US-ASCII
|
|
8
|
+
string: ''
|
|
9
|
+
headers:
|
|
10
|
+
User-Agent:
|
|
11
|
+
- Faraday v0.14.0
|
|
12
|
+
Accept:
|
|
13
|
+
- application/vnd.gathercontent.v0.5+json
|
|
14
|
+
Authorization:
|
|
15
|
+
- Basic YW5kcmV3QGdhdGhlcmNvbnRlbnQuY29tOjJkMmE4YmY2LTA4YzAtNDllNi05NDYwLTI1MTM5ZmRiOGIyNA==
|
|
16
|
+
Accept-Encoding:
|
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
|
18
|
+
response:
|
|
19
|
+
status:
|
|
20
|
+
code: 200
|
|
21
|
+
message: OK
|
|
22
|
+
headers:
|
|
23
|
+
Cache-Control:
|
|
24
|
+
- no-cache
|
|
25
|
+
Content-Type:
|
|
26
|
+
- application/json
|
|
27
|
+
Date:
|
|
28
|
+
- Mon, 26 Feb 2018 04:08:03 GMT
|
|
29
|
+
Server:
|
|
30
|
+
- nginx
|
|
31
|
+
Content-Length:
|
|
32
|
+
- '75'
|
|
33
|
+
Connection:
|
|
34
|
+
- keep-alive
|
|
35
|
+
body:
|
|
36
|
+
encoding: ASCII-8BIT
|
|
37
|
+
string: '{"data":{"id":"123456","name":"Example","slug":"example","timezone":"UTC"}}'
|
|
38
|
+
http_version:
|
|
39
|
+
recorded_at: Mon, 26 Feb 2018 04:08:03 GMT
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: get
|
|
5
|
+
uri: https://api.gathercontent.com/accounts/123456
|
|
6
|
+
body:
|
|
7
|
+
encoding: US-ASCII
|
|
8
|
+
string: ''
|
|
9
|
+
headers:
|
|
10
|
+
User-Agent:
|
|
11
|
+
- Faraday v0.14.0
|
|
12
|
+
Accept:
|
|
13
|
+
- application/vnd.gathercontent.v0.5+json
|
|
14
|
+
Authorization:
|
|
15
|
+
- Basic YW5kcmV3QGdhdGhlcmNvbnRlbnQuY29tOjJkMmE4YmY2LTA4YzAtNDllNi05NDYwLTI1MTM5ZmRiOGIyNA==
|
|
16
|
+
Accept-Encoding:
|
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
|
18
|
+
response:
|
|
19
|
+
status:
|
|
20
|
+
code: 200
|
|
21
|
+
message: OK
|
|
22
|
+
headers:
|
|
23
|
+
Cache-Control:
|
|
24
|
+
- no-cache
|
|
25
|
+
Content-Type:
|
|
26
|
+
- application/json
|
|
27
|
+
Date:
|
|
28
|
+
- Mon, 26 Feb 2018 04:08:03 GMT
|
|
29
|
+
Server:
|
|
30
|
+
- nginx
|
|
31
|
+
Content-Length:
|
|
32
|
+
- '75'
|
|
33
|
+
Connection:
|
|
34
|
+
- keep-alive
|
|
35
|
+
body:
|
|
36
|
+
encoding: ASCII-8BIT
|
|
37
|
+
string: '{"data":{"id":"123456","name":"Example","slug":"example","timezone":"UTC"}}'
|
|
38
|
+
http_version:
|
|
39
|
+
recorded_at: Mon, 26 Feb 2018 04:08:03 GMT
|