noun-project-api 4.0.6 → 5.0.1

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
  SHA256:
3
- metadata.gz: c5df28f17c40d8cd6ec4ad8295fca6e48d8d59c098443d511d73caaed5a92bf9
4
- data.tar.gz: 729be65543ab319b0c0e10bc5f998cdd6cbff7b307a46d3122fab97aacc758bc
3
+ metadata.gz: 65f43c12101b7d89093adca01111f01cc464092b94fbddbd28c20fa6d8e6a73f
4
+ data.tar.gz: fa14a3346d4b5d12a37e07d2e87203d6ff9c30518bd4952feb10e903d1f0661f
5
5
  SHA512:
6
- metadata.gz: 90f0b323d558d9aa757561e0b561d238551840970ca840b317d7d384a572c849e5eff3596803d3d2c9ed925e0aae46c813c19faae340dff43134a01fbf2dfc19
7
- data.tar.gz: e805b9ce65c25c1666d79be078172e3b4e7294ced94e14a07c04224d51ffdaacbc1fe7bbec7f5ded8e8b6fb2eaf317b4d110ee69ad88f456d2583338293c0fdd
6
+ metadata.gz: 8517541b1fe9f2c0d787200e8f29bfe8bd3df5cef592982e47a2c76365c46108e38f7c1182fdf1646a5ee7ba938f0d75ae34c9603abae0917c06690e9dca0e17
7
+ data.tar.gz: fca995494200ed116f842422fc9a1babed64dd48f8fc226093fcf0e910acb526d1ef8140f4d3ae489ae439d6073faa7076ca7be26496850b0ff8be1698b4be66
data/CHANGELOG.md ADDED
@@ -0,0 +1,65 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [5.0.1] - 2026-11-17
10
+ ### Fixed
11
+ - Requests fail with `OAuth::Error` (cross-origin URI not permitted) when the bundle resolves oauth 1.1.9,
12
+ which refuses signed requests to an origin other than the consumer's site. The OAuth consumer is now
13
+ configured with `site: API_BASE`; the signed requests sent are byte-identical to before.
14
+
15
+ ## [5.0.0] - 2026-11-17
16
+ No change to the public API or runtime behavior; the major bump is for the Ruby floor.
17
+
18
+ ### Changed
19
+ - **BREAKING:** Requires Ruby >= 3.4 (was >= 3.2). Development Ruby is 3.4.12.
20
+ - Version now lives in `NounProjectApi::VERSION` (`lib/noun_project_api/version.rb`).
21
+ - Gemspec follows current conventions: `add_dependency`, rubygems metadata URIs, and the packaged
22
+ files are now `lib/`, `README.md`, `CHANGELOG.md` and `LICENSE` (it listed files that did not exist).
23
+ - Development dependencies moved to the `Gemfile` and upgraded to their latest releases
24
+ (rspec 3.13, rubocop 1.92 with rubocop-rspec 3.10, faker 3.8, rake 13.4), bundled with Bundler 4.1.
25
+ - Specs modernized (`described_class`, `let`, spies, `Struct` in place of `OpenStruct`), with added
26
+ coverage for search caching, error responses and Marshal round-trip of cached icons.
27
+
28
+ ### Removed
29
+ - Travis CI config (CI runs on GitHub Actions).
30
+
31
+ ## [3.1.0] - 2020-07-10
32
+ ### Changed
33
+ - Changed is_published attribute to published
34
+ - rubocop update and fixes
35
+ - Switch to symbol based hash access
36
+ - Dropped semver gem
37
+ - Gem updates
38
+ - Add cache TTL support.
39
+ - Switched to Github actions
40
+
41
+ ## [3.0.0] - 2020-07-10
42
+ ### Changed
43
+ - Updated to Ruby 2.7.1
44
+ - Add cache support.
45
+
46
+ ## [2.0.1] - 2018-09-06
47
+ ### Changed
48
+ - Changed `IconRetriever` class' error class from `ArgumentError` to `ServiceError` when responses http code from Noun Project API are other than `200` **BREAKING CHANGE**
49
+
50
+ ## [2.0.0] - 2018-09-06
51
+ ### Added
52
+ - Added `CHANGELOG.md`
53
+ - Added `ServiceError` class to represent errors returned from Noun Project API with additional `code` and `body` attributes
54
+
55
+ ### Changed
56
+ - Changed `Retriever` class' error class from `ArgumentError` to `ServiceError` when responses http code from Noun Project API are other than `200` **BREAKING CHANGE**
57
+
58
+ ### Removed
59
+ - Removed CircleCI support
60
+ - Dropped Rubinius (rbx-2) support
61
+ - Dropped Ruby 1.9 support
62
+
63
+ ## [1.0.0] - 2016-06-16
64
+ ### Added
65
+ - Initial release of `noun-project-api`
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Tailor Brands
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,121 @@
1
+ The Noun Project Ruby API Wrapper
2
+ ===================
3
+
4
+ A Ruby API wrapper for [The Noun Project](https://thenounproject.com/) [API's](https://thenounproject.com/developers/)
5
+
6
+ [![Gem Version](https://badge.fury.io/rb/noun-project-api.svg)](https://badge.fury.io/rb/noun-project-api)
7
+
8
+ ```rb
9
+ gem "noun-project-api", "~> 5.0", require: "noun_project_api"
10
+ ```
11
+
12
+ Requires Ruby 3.4 or newer.
13
+
14
+ ## Missing
15
+
16
+ Current version only wraps the Icon/Icons API's. Feel free to send a pull request with more API's wrapped!
17
+
18
+ ## Usage
19
+
20
+ You need a valid pair of token and secret to use the Gem, you can get these by signing up [here](https://thenounproject.com/developers)
21
+
22
+ *Raises ArgumentError on bad arguments*
23
+
24
+ ### Configuration
25
+ You can use an initializer for example if you're on Rails.
26
+ ```rb
27
+ # initializers/noun_project_api.rb
28
+ NounProjectApi.configure do |config|
29
+ # Will only show public domain icons when running in dev/test envs
30
+ config.public_domain = ['development', 'test'].include?(ENV['RAILS_ENV'])
31
+ end
32
+ ```
33
+
34
+ Cache setup (needs to be an `ActiveSupport::Cache::Store`)
35
+ ```rb
36
+ config.cache = Rails.cache
37
+ config.cache_ttl = 20 # seconds
38
+ ```
39
+
40
+ Defaults to Null store and 1 week TTL.
41
+
42
+ ### Find single icon
43
+ Initialize
44
+ ```rb
45
+ icon_finder = NounProjectApi::IconRetriever.new(token, secret)
46
+ ```
47
+
48
+ Find an Icon by id [source](https://api.thenounproject.com/documentation.html#get--icon-(int-id))
49
+ ```rb
50
+ result = icon_finder.find(1) # Returns a hash of the parsed JSON result.
51
+ ```
52
+
53
+ Find an Icon by slug [source](https://api.thenounproject.com/documentation.html#get--icon-(string-term))
54
+ ```rb
55
+ result = icon_finder.find_by_slug('globe') # Returns a hash of the parsed JSON result.
56
+ ```
57
+
58
+ ### Search icons
59
+ Initialize
60
+ ```rb
61
+ icons_finder = NounProjectApi::IconsRetriever.new(token, secret)
62
+ ```
63
+
64
+ *Optional arguments for both methods are limit, offset and page*
65
+
66
+ Find Icons [source](https://api.thenounproject.com/documentation.html#get--icons-(string-term))
67
+ ```rb
68
+ result = icons_finder.find('cat') # Returns an array of the parsed JSON results.
69
+ ```
70
+
71
+ Get recent Icons [source](https://api.thenounproject.com/documentation.html#get--icons-recent_uploads)
72
+ ```rb
73
+ result = icons_finder.recent_uploads # Returns an array of the parsed JSON results.
74
+ ```
75
+
76
+ ### Find a collection of icons
77
+ Initialize
78
+ ```rb
79
+ collection_finder = NounProjectApi::CollectionRetriever.new(token, secret)
80
+ ```
81
+
82
+ Find a Collection by id [source](http://api.thenounproject.com/documentation.html#get--collection-(int-id))
83
+ ```rb
84
+ result = collection_finder.find(1) # Returns a hash of the parsed JSON result.
85
+ ```
86
+
87
+ Find a Collection by slug [source](http://api.thenounproject.com/documentation.html#get--collection-(slug))
88
+ ```rb
89
+ result = collection_finder.find_by_slug('national-park-service') # Returns a hash of the parsed JSON result.
90
+ ```
91
+
92
+
93
+ #### Resulting objects
94
+ The resulting object is either a NounObjectApi::Icon or an array of ones.
95
+
96
+ ```rb
97
+ result.class # NounProjectApi::Icon
98
+ result.id # 1
99
+ result.public_domain? # true/false
100
+ result.svg_url # url/nil
101
+ result.preview_url # 200 size preview url
102
+ result.preview_url(42) # 42 size preview url
103
+
104
+ # You can always access the original Hash at
105
+ result.original_hash
106
+ ```
107
+
108
+ ## Disclaimer
109
+
110
+ This is completely unofficial and is not related to The Noun Project in any way.
111
+
112
+ ## Contributing
113
+
114
+ 1. Fork it
115
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
116
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
117
+ 4. Push to the branch (`git push origin my-new-feature`)
118
+ 5. Create new Pull Request
119
+
120
+ ## About Tailor Brands
121
+ [Check us out!](https://www.tailorbrands.com)
@@ -10,7 +10,9 @@ module NounProjectApi
10
10
  @secret = secret
11
11
  raise ArgumentError, "Missing token or secret" unless @token && @secret
12
12
 
13
- @access_token = OAuth::AccessToken.new(OAuth::Consumer.new(token, secret))
13
+ # The consumer's site must match the API origin: oauth >= 1.1.9 refuses
14
+ # signed requests to an absolute URL on any other origin.
15
+ @access_token = OAuth::AccessToken.new(OAuth::Consumer.new(token, secret, site: API_BASE))
14
16
  end
15
17
  end
16
18
  end
@@ -7,7 +7,7 @@ module NounProjectApi
7
7
 
8
8
  API_PATH = "/notify/publish"
9
9
 
10
- def report_used(ids)
10
+ def report_used(ids) # rubocop:disable Naming/PredicateMethod -- public API, renaming would break callers
11
11
  ids = [ids] if ids.is_a?(String) || ids.is_a?(Integer)
12
12
  raise ArgumentError, "Missing ids" if ids.nil? || ids.empty?
13
13
 
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NounProjectApi
4
+ VERSION = "5.0.1"
5
+ end
@@ -2,7 +2,9 @@
2
2
 
3
3
  require "oauth"
4
4
  require "active_support/all"
5
+ require "digest"
5
6
  require "json"
7
+ require "noun_project_api/version"
6
8
  require "noun_project_api/errors"
7
9
  require "noun_project_api/connection"
8
10
  require "noun_project_api/icon_retriever"
@@ -21,7 +23,6 @@ module NounProjectApi
21
23
  end
22
24
 
23
25
  def self.configure
24
- self.configuration ||= Configuration.new
25
26
  yield(configuration) if block_given?
26
27
  end
27
28
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noun-project-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.6
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tailor Engineering
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-11-17 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -44,69 +43,15 @@ dependencies:
44
43
  - - "~>"
45
44
  - !ruby/object:Gem::Version
46
45
  version: '1.1'
47
- - !ruby/object:Gem::Dependency
48
- name: faker
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '3.1'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '3.1'
61
- - !ruby/object:Gem::Dependency
62
- name: rake
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '13.0'
68
- type: :development
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '13.0'
75
- - !ruby/object:Gem::Dependency
76
- name: rspec
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - "~>"
80
- - !ruby/object:Gem::Version
81
- version: '3.12'
82
- type: :development
83
- prerelease: false
84
- version_requirements: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - "~>"
87
- - !ruby/object:Gem::Version
88
- version: '3.12'
89
- - !ruby/object:Gem::Dependency
90
- name: rubocop
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: '1'
96
- type: :development
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - "~>"
101
- - !ruby/object:Gem::Version
102
- version: '1'
103
46
  description: A Gem to expose a wrapping API for The Noun Project API's
104
47
  email: sloths@tailorbrands.com
105
48
  executables: []
106
49
  extensions: []
107
50
  extra_rdoc_files: []
108
51
  files:
109
- - Rakefile
52
+ - CHANGELOG.md
53
+ - LICENSE
54
+ - README.md
110
55
  - lib/noun_project_api.rb
111
56
  - lib/noun_project_api/base_item.rb
112
57
  - lib/noun_project_api/collection.rb
@@ -118,22 +63,14 @@ files:
118
63
  - lib/noun_project_api/icons_retriever.rb
119
64
  - lib/noun_project_api/reporter.rb
120
65
  - lib/noun_project_api/retriever.rb
121
- - spec/lib/noun_project_api/base_item_spec.rb
122
- - spec/lib/noun_project_api/collection_retriever_spec.rb
123
- - spec/lib/noun_project_api/collection_spec.rb
124
- - spec/lib/noun_project_api/icon_retriever_spec.rb
125
- - spec/lib/noun_project_api/icon_spec.rb
126
- - spec/lib/noun_project_api/icons_retriever_spec.rb
127
- - spec/lib/noun_project_api/reporter_spec.rb
128
- - spec/lib/noun_project_api/retriever_spec.rb
129
- - spec/lib/noun_project_api_spec.rb
130
- - spec/spec_helper.rb
131
- - spec/support/fakes.rb
66
+ - lib/noun_project_api/version.rb
132
67
  homepage: https://github.com/TailorBrands/noun-project-api
133
68
  licenses:
134
69
  - MIT
135
- metadata: {}
136
- post_install_message:
70
+ metadata:
71
+ source_code_uri: https://github.com/TailorBrands/noun-project-api
72
+ changelog_uri: https://github.com/TailorBrands/noun-project-api/blob/master/CHANGELOG.md
73
+ bug_tracker_uri: https://github.com/TailorBrands/noun-project-api/issues
137
74
  rdoc_options: []
138
75
  require_paths:
139
76
  - lib
@@ -141,26 +78,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
78
  requirements:
142
79
  - - ">="
143
80
  - !ruby/object:Gem::Version
144
- version: '3.2'
81
+ version: '3.4'
145
82
  required_rubygems_version: !ruby/object:Gem::Requirement
146
83
  requirements:
147
84
  - - ">="
148
85
  - !ruby/object:Gem::Version
149
86
  version: '0'
150
87
  requirements: []
151
- rubygems_version: 3.4.19
152
- signing_key:
88
+ rubygems_version: 3.6.9
153
89
  specification_version: 4
154
90
  summary: An API wrapper for The Noun Project API's
155
- test_files:
156
- - spec/lib/noun_project_api/base_item_spec.rb
157
- - spec/lib/noun_project_api/collection_retriever_spec.rb
158
- - spec/lib/noun_project_api/collection_spec.rb
159
- - spec/lib/noun_project_api/icon_retriever_spec.rb
160
- - spec/lib/noun_project_api/icon_spec.rb
161
- - spec/lib/noun_project_api/icons_retriever_spec.rb
162
- - spec/lib/noun_project_api/reporter_spec.rb
163
- - spec/lib/noun_project_api/retriever_spec.rb
164
- - spec/lib/noun_project_api_spec.rb
165
- - spec/spec_helper.rb
166
- - spec/support/fakes.rb
91
+ test_files: []
data/Rakefile DELETED
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler"
4
- Bundler::GemHelper.install_tasks
5
-
6
- $LOAD_PATH.unshift "lib"
7
-
8
- desc "Default: run unit tests."
9
- task default: [:spec]
10
-
11
- require "rspec/core/rake_task"
12
-
13
- desc "Run specs"
14
- RSpec::Core::RakeTask.new do |t|
15
- t.pattern = "./spec/**/*_spec.rb"
16
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
- require "ostruct"
5
-
6
- RSpec.describe NounProjectApi::BaseItem do
7
- it "raises an error on direct initialization" do
8
- data = JSON.parse(Fakes::Results::ICON_VALID)
9
- expect {
10
- NounProjectApi::BaseItem.new(JSON.dump(data["icon"]))
11
- }.to raise_error(NotImplementedError)
12
- end
13
- end
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
- require "ostruct"
5
-
6
- RSpec.describe NounProjectApi::CollectionRetriever do
7
- before :each do
8
- @collection = NounProjectApi::CollectionRetriever.new(Faker::Internet.password(min_length: 16), Faker::Internet.password(min_length: 16))
9
- @valid_hash = JSON.parse(Fakes::Results::COLLECTION_VALID, symbolize_names: true)
10
- @valid_response = OpenStruct.new(
11
- body: Fakes::Results::COLLECTION_VALID,
12
- code: "200"
13
- )
14
-
15
- @missing_response = OpenStruct.new(
16
- code: "404"
17
- )
18
- end
19
-
20
- context "id" do
21
- it "raises an error when no id is provided" do
22
- expect { @collection.find(nil) }.to raise_error(ArgumentError)
23
- end
24
-
25
- it "returns a proper result with a correct id" do
26
- id = 1
27
- expect(@collection.access_token).to receive(
28
- :get
29
- ).with(
30
- "#{NounProjectApi::API_BASE}#{NounProjectApi::CollectionRetriever::API_PATH}#{id}"
31
- ).and_return(
32
- @valid_response
33
- )
34
-
35
- result = @collection.find(id)
36
- expect(result).to be_a(NounProjectApi::Collection)
37
- expect(result.original_hash).to eq(@valid_hash[:collection])
38
- end
39
-
40
- it "raises an error with a missing id" do
41
- id = 1
42
- expect(@collection.access_token).to receive(
43
- :get
44
- ).with(
45
- "#{NounProjectApi::API_BASE}#{NounProjectApi::CollectionRetriever::API_PATH}#{id}"
46
- ).and_return(
47
- @missing_response
48
- )
49
-
50
- expect { @collection.find(id) }.to raise_error(NounProjectApi::ServiceError)
51
- end
52
- end
53
-
54
- context "slug" do
55
- it "raises an error when no slug is provided" do
56
- expect { @collection.find_by_slug(nil) }.to raise_error(ArgumentError)
57
- end
58
-
59
- it "returns a proper result with a correct slug" do
60
- slug = "existing_slug"
61
- expect(@collection.access_token).to receive(
62
- :get
63
- ).with(
64
- "#{NounProjectApi::API_BASE}#{NounProjectApi::CollectionRetriever::API_PATH}#{slug}"
65
- ).and_return(
66
- @valid_response
67
- )
68
-
69
- result = @collection.find(slug)
70
- expect(result).to be_a(NounProjectApi::Collection)
71
- expect(result.original_hash).to eq(@valid_hash[:collection])
72
- end
73
-
74
- it "raises an error with a missing slug" do
75
- slug = "missing_slug"
76
- expect(@collection.access_token).to receive(
77
- :get
78
- ).with(
79
- "#{NounProjectApi::API_BASE}#{NounProjectApi::CollectionRetriever::API_PATH}#{slug}"
80
- ).and_return(
81
- @missing_response
82
- )
83
-
84
- expect { @collection.find_by_slug(slug) }.to raise_error(NounProjectApi::ServiceError)
85
- end
86
- end
87
- end
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
- require "ostruct"
5
-
6
- RSpec.describe NounProjectApi::CollectionRetriever do
7
- it "raises an error on empty initialization input" do
8
- expect { NounProjectApi::Collection.new }.to raise_error(ArgumentError)
9
- end
10
-
11
- it "accepts JSON string input" do
12
- data = JSON.parse(Fakes::Results::COLLECTION_VALID)
13
- expect { NounProjectApi::Collection.new(JSON.dump(data["collection"])) }.to_not raise_error
14
- end
15
-
16
- it "accepts JSON string input with collection encapsulation" do
17
- expect { NounProjectApi::Collection.new(Fakes::Results::COLLECTION_VALID) }.to_not raise_error
18
- end
19
-
20
- it "accepts hash input" do
21
- data = JSON.parse(Fakes::Results::COLLECTION_VALID)
22
- expect { NounProjectApi::Collection.new(data) }.to_not raise_error
23
- end
24
-
25
- context "exposed attributes" do
26
- before :each do
27
- @json = JSON.parse(Fakes::Results::COLLECTION_VALID)
28
- @valid_collection = NounProjectApi::Collection.new(Fakes::Results::COLLECTION_VALID)
29
- end
30
-
31
- it "id as number" do
32
- expect(@valid_collection.id).to be_a(Integer)
33
- expect(@valid_collection.id).to eq(@json["collection"]["id"].to_i)
34
- end
35
-
36
- it "author id as number" do
37
- expect(@valid_collection.author_id).to eq(@json["collection"]["author_id"].to_i)
38
- end
39
-
40
- it "author name" do
41
- expect(@valid_collection.author_name).to eq(@json["collection"]["author"]["name"])
42
- end
43
-
44
- it "icon count as number" do
45
- expect(@valid_collection.icon_count).to eq(@json["collection"]["icon_count"].to_i)
46
- end
47
-
48
- it "is published" do
49
- expect(@valid_collection.published?).to eq(@json["collection"]["is_published"].to_i == 1)
50
- end
51
-
52
- it "builds a simple hash" do
53
- expect(@valid_collection.to_hash).to eq(
54
- id: @valid_collection.id,
55
- author_id: @valid_collection.author_id,
56
- author_name: @valid_collection.author_name,
57
- icon_count: @valid_collection.icon_count,
58
- published: @valid_collection.published?
59
- )
60
- end
61
-
62
- it "json formats the hash" do
63
- expect(@valid_collection.to_json).to eq JSON.dump @valid_collection.to_hash
64
- end
65
- end
66
- end
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
- require "ostruct"
5
-
6
- RSpec.describe NounProjectApi::IconRetriever do
7
- before :each do
8
- @icon = NounProjectApi::IconRetriever.new(Faker::Internet.password(min_length: 16), Faker::Internet.password(min_length: 16))
9
- @valid_hash = JSON.parse(Fakes::Results::ICON_VALID, symbolize_names: true)
10
- @valid_response = OpenStruct.new(
11
- body: Fakes::Results::ICON_VALID,
12
- code: "200"
13
- )
14
-
15
- @missing_response = OpenStruct.new(
16
- code: "404"
17
- )
18
- end
19
-
20
- context "id" do
21
- it "raises an error when no id is provided" do
22
- expect { @icon.find(nil) }.to raise_error(ArgumentError)
23
- end
24
-
25
- it "returns a proper result with a correct id" do
26
- id = 1
27
- expect(@icon.access_token).to receive(
28
- :get
29
- ).with(
30
- "#{NounProjectApi::API_BASE}#{NounProjectApi::IconRetriever::API_PATH}#{id}"
31
- ).and_return(
32
- @valid_response
33
- )
34
-
35
- result = @icon.find(id)
36
- expect(result).to be_a(NounProjectApi::Icon)
37
- expect(result.original_hash).to eq(@valid_hash[:icon])
38
- end
39
-
40
- it "raises an error with a missing id" do
41
- id = 1
42
- expect(@icon.access_token).to receive(
43
- :get
44
- ).with(
45
- "#{NounProjectApi::API_BASE}#{NounProjectApi::IconRetriever::API_PATH}#{id}"
46
- ).and_return(
47
- @missing_response
48
- )
49
-
50
- expect { @icon.find(id) }.to raise_error(NounProjectApi::ServiceError)
51
- end
52
- end
53
-
54
- context "slug" do
55
- it "raises an error when no slug is provided" do
56
- expect { @icon.find_by_slug(nil) }.to raise_error(ArgumentError)
57
- end
58
-
59
- it "returns a proper result with a correct slug" do
60
- slug = "existing_slug"
61
- expect(@icon.access_token).to receive(
62
- :get
63
- ).with(
64
- "#{NounProjectApi::API_BASE}#{NounProjectApi::IconRetriever::API_PATH}#{slug}"
65
- ).and_return(
66
- @valid_response
67
- )
68
-
69
- result = @icon.find(slug)
70
- expect(result).to be_a(NounProjectApi::Icon)
71
- expect(result.original_hash).to eq(@valid_hash[:icon])
72
- end
73
-
74
- it "raises an error with a missing slug" do
75
- slug = "missing_slug"
76
- expect(@icon.access_token).to receive(
77
- :get
78
- ).with(
79
- "#{NounProjectApi::API_BASE}#{NounProjectApi::IconRetriever::API_PATH}#{slug}"
80
- ).and_return(
81
- @missing_response
82
- )
83
-
84
- expect { @icon.find_by_slug(slug) }.to raise_error(NounProjectApi::ServiceError)
85
- end
86
- end
87
- end