noun-project-api 0.0.7 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4bcc5e69be85f084b513b6cc957ccea30627657
4
- data.tar.gz: a57feb45cf2a81a9219d2a0666799b8cf38a4a3f
3
+ metadata.gz: 38b46a0bde8395513cae9b4d2096d15cab2de56d
4
+ data.tar.gz: 5a148071f5a87420443ba2b7affe37bc24e24ba5
5
5
  SHA512:
6
- metadata.gz: 692fa679a1b992274bf53f3cb5fb3c08cbd3764627c8445ae63128f0d4a135f8e691546582e436dc709ba6f4068c232d59f390c6c4999fa508f135337e711457
7
- data.tar.gz: 8d148ecb2aa64473dd605be26e69a0974ebfad4d262bebea536c3b480c162f1e94be9a2ef379cc8d6a3cdefe335037f9c2d19aee02cc4564311a934301248134
6
+ metadata.gz: f964c8927b12370efc633b7c07b7e99ee19ee1081f3c782130f6593c8e1d280cc553e2a03a57da034d6e9bb1e6963c42fdb33c7eeb6363408e4679e8ec575626
7
+ data.tar.gz: 3f394da10b8dff96754c0810c7f2b66ae1894f74dabaac5dae898b5fcdd2703561d19d6ed73abd9083c1b3aaa8d47b64e87ef5c883d9387ae4a5e0ee07f96d7d
@@ -3,4 +3,20 @@ require 'noun-project-api/icons_retriever'
3
3
  require 'noun-project-api/icon'
4
4
 
5
5
  module NounProjectApi
6
+ def self.configuration
7
+ @configuration ||= Configuration.new
8
+ end
9
+
10
+ def self.configure
11
+ self.configuration ||= Configuration.new
12
+ yield(configuration) if block_given?
13
+ end
14
+
15
+ class Configuration
16
+ attr_accessor :public_domain
17
+
18
+ def initialize
19
+ @public_domain = false
20
+ end
21
+ end
6
22
  end
@@ -9,11 +9,11 @@ module NounProjectApi
9
9
  raise ArgumentError.new('Missing search term') unless term
10
10
 
11
11
  search = URI::encode(term)
12
+ search += "?limit_to_public_domain=#{NounProjectApi.configuration.public_domain ? 1 : 0}"
12
13
 
13
14
  args = { "limit" => limit, "offset" => offset, "page" => page }.reject { |k, v| v.nil? }
14
15
  if args.size > 0
15
- search += '?'
16
- args.each { |k, v| search += "#{k}=#{v}&" }
16
+ args.each { |k, v| search += "&#{k}=#{v}" }
17
17
  end
18
18
 
19
19
  result = self.access_token.get("#{API_BASE}#{API_PATH}#{search}")
@@ -60,5 +60,18 @@ RSpec.describe NounProjectApi::IconRetriever do
60
60
  expect(@valid_icon.id).to be_a(Fixnum)
61
61
  expect(@valid_icon.id).to eq(@json["icon"]["id"].to_i)
62
62
  end
63
+
64
+ it 'builds a simple hash' do
65
+ expect(@valid_icon.to_hash).to eq({
66
+ id: @valid_icon.id,
67
+ preview_url_200: @valid_icon.preview_url(NounProjectApi::Icon::PREVIEW_SIZE_200),
68
+ preview_url_84: @valid_icon.preview_url(NounProjectApi::Icon::PREVIEW_SIZE_84),
69
+ preview_url_42: @valid_icon.preview_url(NounProjectApi::Icon::PREVIEW_SIZE_42)
70
+ })
71
+ end
72
+
73
+ it 'json formats the hash' do
74
+ expect(@valid_icon.to_json).to eq JSON.dump @valid_icon.to_hash
75
+ end
63
76
  end
64
77
  end
@@ -68,7 +68,7 @@ RSpec.describe NounProjectApi::IconsRetriever do
68
68
  expect(@icons.access_token).to receive(
69
69
  :get
70
70
  ).with(
71
- "#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{URI::encode(term)}"
71
+ "#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{URI::encode(term)}?limit_to_public_domain=0"
72
72
  ).and_return(
73
73
  valid_response
74
74
  )
@@ -91,7 +91,7 @@ RSpec.describe NounProjectApi::IconsRetriever do
91
91
  expect(@icons.access_token).to receive(
92
92
  :get
93
93
  ).with(
94
- "#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{URI::encode(term)}"
94
+ "#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{URI::encode(term)}?limit_to_public_domain=0"
95
95
  ).and_return(
96
96
  valid_response
97
97
  )
@@ -103,6 +103,31 @@ RSpec.describe NounProjectApi::IconsRetriever do
103
103
  end
104
104
  end
105
105
 
106
+ it 'properly handles public domain only config' do
107
+ valid_hash = JSON.parse(Fakes::Results::ICONS_VALID)
108
+ valid_response = OpenStruct.new(
109
+ body: Fakes::Results::ICONS_VALID,
110
+ code: '200'
111
+ )
112
+
113
+ term = 'some search'
114
+ expect(@icons.access_token).to receive(
115
+ :get
116
+ ).with(
117
+ "#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{URI::encode(term)}?limit_to_public_domain=1"
118
+ ).and_return(
119
+ valid_response
120
+ )
121
+
122
+ NounProjectApi.configuration.public_domain = true
123
+ results = @icons.find(term)
124
+ expect(results.size).to eq(valid_hash["icons"].size)
125
+ results.each do |icon|
126
+ expect(icon).to be_a(NounProjectApi::Icon)
127
+ end
128
+ NounProjectApi.configuration.public_domain = false
129
+ end
130
+
106
131
  it 'returns a proper result with a correct phrase and passes along the args' do
107
132
  valid_response = OpenStruct.new(
108
133
  body: Fakes::Results::ICONS_VALID,
@@ -114,7 +139,7 @@ RSpec.describe NounProjectApi::IconsRetriever do
114
139
  expect(@icons.access_token).to receive(
115
140
  :get
116
141
  ).with(
117
- "#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{URI::encode(term)}?limit=#{limit}&"
142
+ "#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{URI::encode(term)}?limit_to_public_domain=0&limit=#{limit}"
118
143
  ).and_return(
119
144
  valid_response
120
145
  )
@@ -135,7 +160,7 @@ RSpec.describe NounProjectApi::IconsRetriever do
135
160
  expect(@icons.access_token).to receive(
136
161
  :get
137
162
  ).with(
138
- "#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{URI::encode(term)}"
163
+ "#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{URI::encode(term)}?limit_to_public_domain=0"
139
164
  ).and_return(
140
165
  missing_response
141
166
  )
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe NounProjectApi do
4
+ it 'has the correct default' do
5
+ expect(NounProjectApi.configuration.public_domain).to be false
6
+ end
7
+
8
+ it 'sets the correct configuration' do
9
+ expect(NounProjectApi.configuration.public_domain).to be false
10
+
11
+ NounProjectApi.configure do |config|
12
+ config.public_domain = true
13
+ end
14
+
15
+ expect(NounProjectApi.configuration.public_domain).to be true
16
+
17
+ NounProjectApi.configuration.public_domain = false
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noun-project-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nadav Shatz
@@ -88,6 +88,7 @@ files:
88
88
  - spec/lib/noun-project-api/icon_spec.rb
89
89
  - spec/lib/noun-project-api/icons_retriever_spec.rb
90
90
  - spec/lib/noun-project-api/retriever_spec.rb
91
+ - spec/lib/nount_project_api_spec.rb
91
92
  - spec/spec_helper.rb
92
93
  - spec/support/fakes.rb
93
94
  homepage: https://github.com/TailorBrands/noun-project-api
@@ -119,5 +120,6 @@ test_files:
119
120
  - spec/lib/noun-project-api/icon_spec.rb
120
121
  - spec/lib/noun-project-api/icons_retriever_spec.rb
121
122
  - spec/lib/noun-project-api/retriever_spec.rb
123
+ - spec/lib/nount_project_api_spec.rb
122
124
  - spec/spec_helper.rb
123
125
  - spec/support/fakes.rb