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,53 @@
|
|
|
1
|
+
require "base64"
|
|
2
|
+
|
|
3
|
+
module GatherContent
|
|
4
|
+
module Api
|
|
5
|
+
class Item < Base
|
|
6
|
+
attr_accessor :item_id
|
|
7
|
+
|
|
8
|
+
def initialize(item_id, data = nil)
|
|
9
|
+
raise ArgumentError, "Item_id is required!" if item_id.nil?
|
|
10
|
+
@item_id = item_id
|
|
11
|
+
@data = data
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def [](key)
|
|
15
|
+
fetch[key]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def save(config)
|
|
19
|
+
encoded = Base64.strict_encode64(config.to_json)
|
|
20
|
+
result = post_json({config: encoded}, "#{path}/save")
|
|
21
|
+
if result.status == 202
|
|
22
|
+
true
|
|
23
|
+
else
|
|
24
|
+
raise GatherContent::Error::RequestError.new(result)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def apply_template(template_id)
|
|
29
|
+
post_save({ "template_id" => template_id }, "#{path}/apply_template")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def choose_status(status_id)
|
|
33
|
+
post_save({ "status_id" => status_id }, "#{path}/choose_status")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
def post_save(params, path)
|
|
38
|
+
result = post_json(params, path)
|
|
39
|
+
if result.status == 202
|
|
40
|
+
true
|
|
41
|
+
else
|
|
42
|
+
raise GatherContent::Error::RequestError.new(result)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def path
|
|
47
|
+
@path ||= "/items/#{item_id}"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def params; end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require "base64"
|
|
2
|
+
|
|
3
|
+
module GatherContent
|
|
4
|
+
module Api
|
|
5
|
+
class Items < Base
|
|
6
|
+
include Enumerable
|
|
7
|
+
attr_accessor :project_id
|
|
8
|
+
|
|
9
|
+
def initialize(project_id)
|
|
10
|
+
raise ArgumentError, "Project_id is required!" if project_id.nil?
|
|
11
|
+
@project_id = project_id
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def each(&block)
|
|
15
|
+
fetch.each do |item|
|
|
16
|
+
yield GatherContent::Api::Item.new(item['id'], item)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create(data)
|
|
21
|
+
data.delete("parent_id") if data["parent_id"].nil? || data["parent_id"].empty?
|
|
22
|
+
data.delete("template_id") if data["template_id"].nil? || data["template_id"].empty?
|
|
23
|
+
|
|
24
|
+
config = data.delete("config")
|
|
25
|
+
data["config"] = Base64.strict_encode64(config.to_json) unless config.nil? || config.empty?
|
|
26
|
+
|
|
27
|
+
raise ArgumentError, "name is required!" if data["name"].nil? || data["name"].empty?
|
|
28
|
+
|
|
29
|
+
result = post_json(data.merge({ 'project_id' => @project_id }))
|
|
30
|
+
|
|
31
|
+
if result.status == 202
|
|
32
|
+
item_id = result.headers['location'].split('/').last
|
|
33
|
+
GatherContent::Api::Item.new(item_id)
|
|
34
|
+
else
|
|
35
|
+
raise GatherContent::Error::RequestError.new(result)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
def params
|
|
41
|
+
{ project_id: project_id }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def path
|
|
45
|
+
@path ||= '/items'
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module GatherContent
|
|
2
|
+
module Api
|
|
3
|
+
class Project < Base
|
|
4
|
+
attr_accessor :project_id
|
|
5
|
+
|
|
6
|
+
def initialize(project_id, data = nil)
|
|
7
|
+
raise ArgumentError, "project_id is required!" if project_id.nil?
|
|
8
|
+
@project_id = project_id
|
|
9
|
+
@data = data
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def [](key)
|
|
13
|
+
fetch[key]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def path
|
|
19
|
+
@path ||= "/projects/#{project_id}"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def params; end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module GatherContent
|
|
2
|
+
module Api
|
|
3
|
+
class Projects < Base
|
|
4
|
+
attr_accessor :account_id
|
|
5
|
+
include Enumerable
|
|
6
|
+
|
|
7
|
+
def initialize(account_id)
|
|
8
|
+
raise ArgumentError, "account_id is required!" if account_id.nil?
|
|
9
|
+
@account_id = account_id
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def each(&block)
|
|
13
|
+
fetch.each do |project|
|
|
14
|
+
yield GatherContent::Api::Project.new(project['id'], project)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def create(data)
|
|
19
|
+
data.delete("type") if data["type"].nil? || data["type"].empty?
|
|
20
|
+
|
|
21
|
+
raise ArgumentError, "name is required!" if data["name"].nil? || data["name"].empty?
|
|
22
|
+
raise ArgumentError, "type is invalid!" unless valid_type?(data["type"])
|
|
23
|
+
|
|
24
|
+
result = post_json(data.merge({ 'account_id' => @account_id }))
|
|
25
|
+
|
|
26
|
+
if result.status == 202
|
|
27
|
+
project_id = result.headers['location'].split('/').last
|
|
28
|
+
GatherContent::Api::Project.new(project_id)
|
|
29
|
+
else
|
|
30
|
+
raise GatherContent::Error::RequestError.new(result)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def params
|
|
37
|
+
{ account_id: @account_id }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def path
|
|
41
|
+
@path ||= '/projects'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def valid_type?(type)
|
|
45
|
+
return type = "other" if type.nil? || type.empty?
|
|
46
|
+
types = %w{website-build ongoing-website-content marketing-editorial-content email-marketing-content other}
|
|
47
|
+
types.include?(type)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module GatherContent
|
|
2
|
+
module Api
|
|
3
|
+
class Status < Base
|
|
4
|
+
attr_accessor :project_id, :status_id
|
|
5
|
+
|
|
6
|
+
def initialize(project_id, status_id, data = nil)
|
|
7
|
+
raise ArgumentError, "project_id is required!" if project_id.nil?
|
|
8
|
+
raise ArgumentError, "status_id is required!" if status_id.nil?
|
|
9
|
+
@project_id = project_id
|
|
10
|
+
@status_id = status_id
|
|
11
|
+
@data = data
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def [](key)
|
|
15
|
+
fetch[key]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
def path
|
|
20
|
+
@path ||= "/projects/#{project_id}/statuses/#{status_id}"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def params; end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module GatherContent
|
|
2
|
+
module Api
|
|
3
|
+
|
|
4
|
+
class Statuses < Base
|
|
5
|
+
attr_accessor :project_id
|
|
6
|
+
include Enumerable
|
|
7
|
+
|
|
8
|
+
def initialize(project_id)
|
|
9
|
+
raise ArgumentError, "project_id is required!" if project_id.nil?
|
|
10
|
+
@project_id = project_id
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def each(&block)
|
|
14
|
+
fetch.each do |status|
|
|
15
|
+
yield GatherContent::Api::Status.new(@project_id, status['id'], status)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
def path
|
|
21
|
+
@path ||= "/projects/#{project_id}/statuses"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def params; end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module GatherContent
|
|
2
|
+
module Api
|
|
3
|
+
class Template < Base
|
|
4
|
+
attr_accessor :template_id
|
|
5
|
+
|
|
6
|
+
def initialize(template_id, data = nil)
|
|
7
|
+
raise ArgumentError, "Template_id is required!" if template_id.nil?
|
|
8
|
+
@template_id = template_id
|
|
9
|
+
@data = data
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def [](key)
|
|
13
|
+
fetch[key]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def path
|
|
19
|
+
@path ||= "/templates/#{template_id}"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def params; end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module GatherContent
|
|
2
|
+
module Api
|
|
3
|
+
class Templates < Base
|
|
4
|
+
attr_accessor :project_id
|
|
5
|
+
include Enumerable
|
|
6
|
+
|
|
7
|
+
def initialize(project_id)
|
|
8
|
+
raise ArgumentError, "project_id is required!" if project_id.nil?
|
|
9
|
+
@project_id = project_id
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def each(&block)
|
|
13
|
+
fetch.each do |template|
|
|
14
|
+
yield GatherContent::Api::Template.new(template['id'], template)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def params
|
|
21
|
+
{ project_id: @project_id }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def path
|
|
25
|
+
@path ||= '/templates'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def valid_type?(type)
|
|
29
|
+
return type = "other" if type.nil? || type.empty?
|
|
30
|
+
types = %w{website-build ongoing-website-content marketing-editorial-content email-marketing-content other}
|
|
31
|
+
types.include?(type)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module GatherContent
|
|
2
|
+
module Api
|
|
3
|
+
autoload :Config, 'gather_content/api/config'
|
|
4
|
+
autoload :Base, 'gather_content/api/base'
|
|
5
|
+
autoload :Me, 'gather_content/api/me'
|
|
6
|
+
autoload :Accounts, 'gather_content/api/accounts'
|
|
7
|
+
autoload :Account, 'gather_content/api/account'
|
|
8
|
+
autoload :Projects, 'gather_content/api/projects'
|
|
9
|
+
autoload :Project, 'gather_content/api/project'
|
|
10
|
+
autoload :Items, 'gather_content/api/items'
|
|
11
|
+
autoload :Item, 'gather_content/api/item'
|
|
12
|
+
autoload :Statuses, 'gather_content/api/statuses'
|
|
13
|
+
autoload :Status, 'gather_content/api/status'
|
|
14
|
+
autoload :Files, 'gather_content/api/files'
|
|
15
|
+
autoload :File, 'gather_content/api/file'
|
|
16
|
+
autoload :Templates, 'gather_content/api/templates'
|
|
17
|
+
autoload :Template, 'gather_content/api/template'
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module GatherContent
|
|
2
|
+
module Error
|
|
3
|
+
class RequestError < StandardError
|
|
4
|
+
attr_reader :response, :status
|
|
5
|
+
|
|
6
|
+
def initialize(response)
|
|
7
|
+
@response = response
|
|
8
|
+
@status = response.status
|
|
9
|
+
|
|
10
|
+
super(parse_message(response))
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
def parse_message(response)
|
|
15
|
+
parsed = JSON.parse(response.body)
|
|
16
|
+
|
|
17
|
+
return response.body unless parsed.is_a?(Hash)
|
|
18
|
+
return parsed['data'].join(' ') if parsed['data'].is_a?(Array)
|
|
19
|
+
|
|
20
|
+
if parsed.is_a?(Hash) && parsed['data']
|
|
21
|
+
data = parsed['data']
|
|
22
|
+
|
|
23
|
+
return data['message'] if data['message']
|
|
24
|
+
return data.to_s
|
|
25
|
+
elsif parsed.is_a?(Hash) && parsed['error']
|
|
26
|
+
parsed['error']
|
|
27
|
+
else
|
|
28
|
+
parsed['data'].to_s
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe GatherContent::Api::Account, vcr: true do
|
|
4
|
+
let(:account_id) { 123456 }
|
|
5
|
+
let(:account) { GatherContent::Api::Account.new(account_id) }
|
|
6
|
+
|
|
7
|
+
describe '.new' do
|
|
8
|
+
subject { account }
|
|
9
|
+
|
|
10
|
+
it { is_expected.to be_a GatherContent::Api::Account }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '#fetch' do
|
|
14
|
+
subject { account.fetch }
|
|
15
|
+
it { is_expected.to be_a Hash }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "[]" do
|
|
19
|
+
subject { account }
|
|
20
|
+
|
|
21
|
+
it "returns the data related to the supplied key" do
|
|
22
|
+
expect(subject["id"]).to eq("123456")
|
|
23
|
+
expect(subject["name"]).to eq("Example")
|
|
24
|
+
expect(subject["slug"]).to eq("example")
|
|
25
|
+
expect(subject["timezone"]).to eq("UTC")
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe GatherContent::Api::Accounts, vcr: true do
|
|
4
|
+
let(:accounts) { GatherContent::Api::Accounts.new }
|
|
5
|
+
|
|
6
|
+
describe '#each' do
|
|
7
|
+
subject { accounts }
|
|
8
|
+
|
|
9
|
+
it { is_expected.to be_a Enumerable }
|
|
10
|
+
|
|
11
|
+
it 'should contain Account objects' do
|
|
12
|
+
subject.each do |account|
|
|
13
|
+
expect(account).to be_a GatherContent::Api::Account
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'should have memoized data' do
|
|
18
|
+
expect(subject.first["id"]).to eq("123456")
|
|
19
|
+
expect(subject.first["name"]).to eq("Example")
|
|
20
|
+
expect(subject.first["slug"]).to eq("example")
|
|
21
|
+
expect(subject.first["timezone"]).to eq("UTC")
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'climate_control'
|
|
3
|
+
|
|
4
|
+
describe GatherContent::Api::Config do
|
|
5
|
+
subject { GatherContent::Api::Config.instance }
|
|
6
|
+
|
|
7
|
+
let(:username) { "default" }
|
|
8
|
+
let(:api_key) { "a2d8b22c-25cc-4f45-8892-2298ccf70f47" }
|
|
9
|
+
let(:host) { nil }
|
|
10
|
+
let(:port) { nil }
|
|
11
|
+
|
|
12
|
+
around do |example|
|
|
13
|
+
env = {
|
|
14
|
+
GATHER_CONTENT_API_USERNAME: username,
|
|
15
|
+
GATHER_CONTENT_API_KEY: api_key,
|
|
16
|
+
GATHER_CONTENT_API_HOST: host,
|
|
17
|
+
GATHER_CONTENT_API_PORT: port
|
|
18
|
+
}
|
|
19
|
+
ClimateControl.modify env do
|
|
20
|
+
example.run
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe '#default' do
|
|
25
|
+
it "uses the value from GATHER_CONTENT_API_USERNAME" do
|
|
26
|
+
expect(subject.username).to eq(username)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "uses the value from GATHER_CONTENT_API_KEY" do
|
|
30
|
+
expect(subject.api_key).to eq(api_key)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe "with GATHER_CONTENT_API_HOST" do
|
|
34
|
+
let(:host) { "https://env.gathercontent.com" }
|
|
35
|
+
|
|
36
|
+
it "uses the value from GATHER_CONTENT_API_HOST" do
|
|
37
|
+
expect(subject.host).to eq(host)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe "without GATHER_CONTENT_API_HOST" do
|
|
42
|
+
it "uses https://api.gathercontent.com" do
|
|
43
|
+
expect(subject.host).to eq("https://api.gathercontent.com")
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe "with GATHER_CONTENT_API_PORT" do
|
|
48
|
+
let(:port) { "1443" }
|
|
49
|
+
|
|
50
|
+
it "uses the value from GATHER_CONTENT_API_PORT" do
|
|
51
|
+
expect(subject.port).to eq(port)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe "without GATHER_CONTENT_API_PORT" do
|
|
56
|
+
it "uses 443" do
|
|
57
|
+
expect(subject.port).to eq("443")
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
describe '#run' do
|
|
63
|
+
let(:username) { "example" }
|
|
64
|
+
let(:api_key) { "baa89326-f1be-4959-93e5-effb204e5a6f" }
|
|
65
|
+
let(:host) { "https://specialhost.gathercontent.com" }
|
|
66
|
+
let(:port) { "8443" }
|
|
67
|
+
|
|
68
|
+
before(:each) do
|
|
69
|
+
GatherContent::Api::Config.run do |config|
|
|
70
|
+
config.username = username
|
|
71
|
+
config.api_key = api_key
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
after(:each) do
|
|
76
|
+
GatherContent::Api::Config.run do |config|
|
|
77
|
+
config.username = nil
|
|
78
|
+
config.api_key = nil
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "stores the username" do
|
|
83
|
+
expect(subject.username).to eq(username)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "stores the api_key" do
|
|
87
|
+
expect(subject.api_key).to eq(api_key)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "stores the host" do
|
|
91
|
+
expect(subject.host).to eq(host)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "stores the port" do
|
|
95
|
+
expect(subject.port).to eq(port)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe GatherContent::Api::Files, vcr: true do
|
|
4
|
+
let(:item_id) { 123456 }
|
|
5
|
+
let(:files) { GatherContent::Api::Files.new(item_id) }
|
|
6
|
+
|
|
7
|
+
describe '.new' do
|
|
8
|
+
subject { files }
|
|
9
|
+
|
|
10
|
+
context 'when project id is passed in' do
|
|
11
|
+
it { is_expected.to be_a GatherContent::Api::Files }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context 'when project 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 '#each' do
|
|
23
|
+
subject { files }
|
|
24
|
+
|
|
25
|
+
it { is_expected.to be_a Enumerable }
|
|
26
|
+
|
|
27
|
+
it 'should contain File objects' do
|
|
28
|
+
subject.each do |file|
|
|
29
|
+
expect(file).to be_a GatherContent::Api::File
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'should have memoized data' do
|
|
34
|
+
expect(subject.first["id"]).to eq(1)
|
|
35
|
+
expect(subject.first["user_id"]).to eq(1)
|
|
36
|
+
expect(subject.first["item_id"]).to eq(123456)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|