noun-project-api 4.0.4 → 5.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 +4 -4
- data/CHANGELOG.md +59 -0
- data/LICENSE +22 -0
- data/README.md +121 -0
- data/lib/noun_project_api/reporter.rb +1 -1
- data/lib/noun_project_api/version.rb +5 -0
- data/lib/noun_project_api.rb +2 -1
- metadata +21 -90
- data/Rakefile +0 -16
- data/spec/lib/noun_project_api/base_item_spec.rb +0 -13
- data/spec/lib/noun_project_api/collection_retriever_spec.rb +0 -87
- data/spec/lib/noun_project_api/collection_spec.rb +0 -66
- data/spec/lib/noun_project_api/icon_retriever_spec.rb +0 -87
- data/spec/lib/noun_project_api/icon_spec.rb +0 -79
- data/spec/lib/noun_project_api/icons_retriever_spec.rb +0 -174
- data/spec/lib/noun_project_api/reporter_spec.rb +0 -96
- data/spec/lib/noun_project_api/retriever_spec.rb +0 -22
- data/spec/lib/noun_project_api_spec.rb +0 -21
- data/spec/spec_helper.rb +0 -14
- data/spec/support/fakes.rb +0 -395
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
require "ostruct"
|
|
5
|
-
|
|
6
|
-
RSpec.describe NounProjectApi::IconRetriever do
|
|
7
|
-
it "raises an error on empty initialization input" do
|
|
8
|
-
expect { NounProjectApi::Icon.new }.to raise_error(ArgumentError)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "accepts JSON string input" do
|
|
12
|
-
data = JSON.parse(Fakes::Results::ICON_VALID)
|
|
13
|
-
expect { NounProjectApi::Icon.new(JSON.dump(data["icon"])) }.to_not raise_error
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "accepts JSON string input with icon encapsulation" do
|
|
17
|
-
expect { NounProjectApi::Icon.new(Fakes::Results::ICON_VALID) }.to_not raise_error
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "accepts hash input" do
|
|
21
|
-
data = JSON.parse(Fakes::Results::ICON_VALID)
|
|
22
|
-
expect { NounProjectApi::Icon.new(data) }.to_not raise_error
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
context "exposed attributes" do
|
|
26
|
-
before :each do
|
|
27
|
-
@json = JSON.parse(Fakes::Results::ICON_VALID)
|
|
28
|
-
@valid_icon = NounProjectApi::Icon.new(Fakes::Results::ICON_VALID)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "public domain" do
|
|
32
|
-
expect(@valid_icon.public_domain?).to eq(@json["icon"]["license_description"] == "public-domain")
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "SVG url" do
|
|
36
|
-
expect(@valid_icon.svg_url).to eq(@json["icon"]["icon_url"])
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it "nil on missing SVG url" do
|
|
40
|
-
@json["icon"].delete("icon_url")
|
|
41
|
-
icon = NounProjectApi::Icon.new(@json)
|
|
42
|
-
expect(icon.svg_url).to be_nil
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it "preview url defaults at 200 size" do
|
|
46
|
-
expect(@valid_icon.preview_url).to eq(@json["icon"]["preview_url"])
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "preview url for 200 size" do
|
|
50
|
-
expect(@valid_icon.preview_url(NounProjectApi::Icon::PREVIEW_SIZE_200)).to eq(@json["icon"]["preview_url"])
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it "preview url for 84 size" do
|
|
54
|
-
expect(@valid_icon.preview_url(NounProjectApi::Icon::PREVIEW_SIZE_84)).to eq(@json["icon"]["preview_url_84"])
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it "preview url for 42 size" do
|
|
58
|
-
expect(@valid_icon.preview_url(NounProjectApi::Icon::PREVIEW_SIZE_42)).to eq(@json["icon"]["preview_url_42"])
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "id as number" do
|
|
62
|
-
expect(@valid_icon.id).to be_a(Integer)
|
|
63
|
-
expect(@valid_icon.id).to eq(@json["icon"]["id"].to_i)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it "builds a simple hash" do
|
|
67
|
-
expect(@valid_icon.to_hash).to eq(
|
|
68
|
-
id: @valid_icon.id,
|
|
69
|
-
preview_url_200: @valid_icon.preview_url(NounProjectApi::Icon::PREVIEW_SIZE_200),
|
|
70
|
-
preview_url_84: @valid_icon.preview_url(NounProjectApi::Icon::PREVIEW_SIZE_84),
|
|
71
|
-
preview_url_42: @valid_icon.preview_url(NounProjectApi::Icon::PREVIEW_SIZE_42)
|
|
72
|
-
)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it "json formats the hash" do
|
|
76
|
-
expect(@valid_icon.to_json).to eq JSON.dump @valid_icon.to_hash
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.describe NounProjectApi::IconsRetriever do
|
|
6
|
-
before :each do
|
|
7
|
-
@icons = NounProjectApi::IconsRetriever.new(Faker::Internet.password(min_length: 16), Faker::Internet.password(min_length: 16))
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
context "recent uploads" do
|
|
11
|
-
it "returns the recent uploads" do
|
|
12
|
-
valid_hash = JSON.parse(Fakes::Results::ICONS_RECENT_VALID)
|
|
13
|
-
valid_response = OpenStruct.new(
|
|
14
|
-
body: Fakes::Results::ICONS_RECENT_VALID,
|
|
15
|
-
code: "200"
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
expect(@icons.access_token).to receive(
|
|
19
|
-
:get
|
|
20
|
-
).with(
|
|
21
|
-
"#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}recent_uploads?"
|
|
22
|
-
).and_return(
|
|
23
|
-
valid_response
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
results = @icons.recent_uploads
|
|
27
|
-
expect(results.size).to eq(valid_hash["recent_uploads"].size)
|
|
28
|
-
results.each do |icon|
|
|
29
|
-
expect(icon).to be_a(NounProjectApi::Icon)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "returns the recent uploads and passes limit when passed" do
|
|
34
|
-
valid_response = OpenStruct.new(
|
|
35
|
-
body: Fakes::Results::ICONS_RECENT_VALID,
|
|
36
|
-
code: "200"
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
limit = 3
|
|
40
|
-
|
|
41
|
-
expect(@icons.access_token).to receive(
|
|
42
|
-
:get
|
|
43
|
-
).with(
|
|
44
|
-
"#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}recent_uploads?limit=#{limit}"
|
|
45
|
-
).and_return(
|
|
46
|
-
valid_response
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
results = @icons.recent_uploads(limit)
|
|
50
|
-
expect(results.size).to eq(limit)
|
|
51
|
-
results.each do |icon|
|
|
52
|
-
expect(icon).to be_a(NounProjectApi::Icon)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
context "Icons search" do
|
|
58
|
-
it "raises an error when no phrase is provided" do
|
|
59
|
-
expect { @icons.find(nil) }.to raise_error(ArgumentError)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it "properly URI encodes search patterns" do
|
|
63
|
-
valid_hash = JSON.parse(Fakes::Results::ICONS_VALID)
|
|
64
|
-
valid_response = OpenStruct.new(
|
|
65
|
-
body: Fakes::Results::ICONS_VALID,
|
|
66
|
-
code: "200"
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
term = 'some search with ",] bad chars'
|
|
70
|
-
expect(@icons.access_token).to receive(
|
|
71
|
-
:get
|
|
72
|
-
).with(
|
|
73
|
-
"#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{OAuth::Helper.escape(term)}?limit_to_public_domain=0"
|
|
74
|
-
).and_return(
|
|
75
|
-
valid_response
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
results = @icons.find(term)
|
|
79
|
-
expect(results.size).to eq(valid_hash["icons"].size)
|
|
80
|
-
results.each do |icon|
|
|
81
|
-
expect(icon).to be_a(NounProjectApi::Icon)
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "returns a proper result with a correct phrase" do
|
|
86
|
-
valid_hash = JSON.parse(Fakes::Results::ICONS_VALID)
|
|
87
|
-
valid_response = OpenStruct.new(
|
|
88
|
-
body: Fakes::Results::ICONS_VALID,
|
|
89
|
-
code: "200"
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
term = "some search"
|
|
93
|
-
expect(@icons.access_token).to receive(
|
|
94
|
-
:get
|
|
95
|
-
).with(
|
|
96
|
-
"#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{OAuth::Helper.escape(term)}?limit_to_public_domain=0"
|
|
97
|
-
).and_return(
|
|
98
|
-
valid_response
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
results = @icons.find(term)
|
|
102
|
-
expect(results.size).to eq(valid_hash["icons"].size)
|
|
103
|
-
results.each do |icon|
|
|
104
|
-
expect(icon).to be_a(NounProjectApi::Icon)
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
it "properly handles public domain only config" do
|
|
109
|
-
valid_hash = JSON.parse(Fakes::Results::ICONS_VALID)
|
|
110
|
-
valid_response = OpenStruct.new(
|
|
111
|
-
body: Fakes::Results::ICONS_VALID,
|
|
112
|
-
code: "200"
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
term = "some search"
|
|
116
|
-
expect(@icons.access_token).to receive(
|
|
117
|
-
:get
|
|
118
|
-
).with(
|
|
119
|
-
"#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{OAuth::Helper.escape(term)}?limit_to_public_domain=1"
|
|
120
|
-
).and_return(
|
|
121
|
-
valid_response
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
NounProjectApi.configuration.public_domain = true
|
|
125
|
-
results = @icons.find(term)
|
|
126
|
-
expect(results.size).to eq(valid_hash["icons"].size)
|
|
127
|
-
results.each do |icon|
|
|
128
|
-
expect(icon).to be_a(NounProjectApi::Icon)
|
|
129
|
-
end
|
|
130
|
-
NounProjectApi.configuration.public_domain = false
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
it "returns a proper result with a correct phrase and passes the args" do
|
|
134
|
-
valid_response = OpenStruct.new(
|
|
135
|
-
body: Fakes::Results::ICONS_VALID,
|
|
136
|
-
code: "200"
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
term = "some search"
|
|
140
|
-
limit = 4
|
|
141
|
-
expect(@icons.access_token).to receive(
|
|
142
|
-
:get
|
|
143
|
-
).with(
|
|
144
|
-
"#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{OAuth::Helper.escape(term)}?limit=#{limit}&limit_to_public_domain=0"
|
|
145
|
-
).and_return(
|
|
146
|
-
valid_response
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
results = @icons.find(term, limit)
|
|
150
|
-
expect(results.size).to eq(limit)
|
|
151
|
-
results.each do |icon|
|
|
152
|
-
expect(icon).to be_a(NounProjectApi::Icon)
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
it "returns an empty array for no result" do
|
|
157
|
-
missing_response = OpenStruct.new(
|
|
158
|
-
code: "404"
|
|
159
|
-
)
|
|
160
|
-
|
|
161
|
-
term = "missing search"
|
|
162
|
-
expect(@icons.access_token).to receive(
|
|
163
|
-
:get
|
|
164
|
-
).with(
|
|
165
|
-
"#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{OAuth::Helper.escape(term)}?limit_to_public_domain=0"
|
|
166
|
-
).and_return(
|
|
167
|
-
missing_response
|
|
168
|
-
)
|
|
169
|
-
|
|
170
|
-
results = @icons.find(term)
|
|
171
|
-
expect(results.size).to eq(0)
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
end
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.describe NounProjectApi::Reporter do
|
|
6
|
-
it "raises an error when initialized without token" do
|
|
7
|
-
expect { NounProjectApi::Reporter.new(nil, Faker::Internet.password(min_length: 16)) }.to raise_error(ArgumentError)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it "raises an error when initialized without secret" do
|
|
11
|
-
expect { NounProjectApi::Reporter.new(Faker::Internet.password(min_length: 16), nil) }.to raise_error(ArgumentError)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "initializes the values properly" do
|
|
15
|
-
token = Faker::Internet.password(min_length: 16)
|
|
16
|
-
secret = Faker::Internet.password(min_length: 16)
|
|
17
|
-
reporter = NounProjectApi::Reporter.new(token, secret)
|
|
18
|
-
|
|
19
|
-
expect(reporter.token).to eq(token)
|
|
20
|
-
expect(reporter.secret).to eq(secret)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
context "reports ids usage" do
|
|
24
|
-
before :each do
|
|
25
|
-
token = Faker::Internet.password(min_length: 16)
|
|
26
|
-
secret = Faker::Internet.password(min_length: 16)
|
|
27
|
-
@reporter = NounProjectApi::Reporter.new(token, secret)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "reports a singular id" do
|
|
31
|
-
valid_response = OpenStruct.new(
|
|
32
|
-
body: Fakes::Results::REPORTED_ONE,
|
|
33
|
-
code: "200"
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
id = 122
|
|
37
|
-
|
|
38
|
-
expect(@reporter.access_token).to receive(
|
|
39
|
-
:post
|
|
40
|
-
).with(
|
|
41
|
-
"#{NounProjectApi::API_BASE}#{NounProjectApi::Reporter::API_PATH}",
|
|
42
|
-
{ icons: id.to_s }.to_json,
|
|
43
|
-
"Accept" => "application/json", "Content-Type" => "application/json"
|
|
44
|
-
).and_return(
|
|
45
|
-
valid_response
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
result = @reporter.report_used(id)
|
|
49
|
-
expect(result).to be true
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it "reports a singular id for a string" do
|
|
53
|
-
valid_response = OpenStruct.new(
|
|
54
|
-
body: Fakes::Results::REPORTED_ONE,
|
|
55
|
-
code: "200"
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
id = "122"
|
|
59
|
-
|
|
60
|
-
expect(@reporter.access_token).to receive(
|
|
61
|
-
:post
|
|
62
|
-
).with(
|
|
63
|
-
"#{NounProjectApi::API_BASE}#{NounProjectApi::Reporter::API_PATH}",
|
|
64
|
-
{ icons: id }.to_json,
|
|
65
|
-
"Accept" => "application/json", "Content-Type" => "application/json"
|
|
66
|
-
).and_return(
|
|
67
|
-
valid_response
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
result = @reporter.report_used(id)
|
|
71
|
-
expect(result).to be true
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "reports multiple ids" do
|
|
75
|
-
valid_response = OpenStruct.new(
|
|
76
|
-
body: Fakes::Results::REPORTED_ONE,
|
|
77
|
-
code: "200"
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
ids = [122, 4541, 342_11, 4352]
|
|
81
|
-
|
|
82
|
-
expect(@reporter.access_token).to receive(
|
|
83
|
-
:post
|
|
84
|
-
).with(
|
|
85
|
-
"#{NounProjectApi::API_BASE}#{NounProjectApi::Reporter::API_PATH}",
|
|
86
|
-
{ icons: ids.join(",") }.to_json,
|
|
87
|
-
"Accept" => "application/json", "Content-Type" => "application/json"
|
|
88
|
-
).and_return(
|
|
89
|
-
valid_response
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
result = @reporter.report_used(ids)
|
|
93
|
-
expect(result).to be true
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.describe NounProjectApi::Retriever do
|
|
6
|
-
it "raises an error when initialized without token" do
|
|
7
|
-
expect { NounProjectApi::Retriever.new(nil, Faker::Internet.password(min_length: 16)) }.to raise_error(ArgumentError)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it "raises an error when initialized without secret" do
|
|
11
|
-
expect { NounProjectApi::Retriever.new(Faker::Internet.password(min_length: 16), nil) }.to raise_error(ArgumentError)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "initializes the values properly" do
|
|
15
|
-
token = Faker::Internet.password(min_length: 16)
|
|
16
|
-
secret = Faker::Internet.password(min_length: 16)
|
|
17
|
-
retriever = NounProjectApi::Retriever.new(token, secret)
|
|
18
|
-
|
|
19
|
-
expect(retriever.token).to eq(token)
|
|
20
|
-
expect(retriever.secret).to eq(secret)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.describe NounProjectApi do
|
|
6
|
-
it "has the correct default" do
|
|
7
|
-
expect(NounProjectApi.configuration.public_domain).to be false
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it "sets the correct configuration" do
|
|
11
|
-
expect(NounProjectApi.configuration.public_domain).to be false
|
|
12
|
-
|
|
13
|
-
NounProjectApi.configure do |config|
|
|
14
|
-
config.public_domain = true
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
expect(NounProjectApi.configuration.public_domain).to be true
|
|
18
|
-
|
|
19
|
-
NounProjectApi.configuration.public_domain = false
|
|
20
|
-
end
|
|
21
|
-
end
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "bundler/setup"
|
|
4
|
-
require "noun_project_api"
|
|
5
|
-
require "faker"
|
|
6
|
-
require "json"
|
|
7
|
-
|
|
8
|
-
require_relative "support/fakes"
|
|
9
|
-
|
|
10
|
-
RSpec.configure do |config|
|
|
11
|
-
config.disable_monkey_patching!
|
|
12
|
-
config.formatter = "documentation"
|
|
13
|
-
config.color = true
|
|
14
|
-
end
|