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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff91ff1e25311df4f15fdbbb2bab7340f27b911be4dfaa7000a503605fa1f7ee
4
- data.tar.gz: b51b6dfa26b2a09ddcdedf1778a299b98c5040f9eb2fb32b5b0c910469672012
3
+ metadata.gz: abb76e3c819b291cea5d99748c2dc5f8f1ae460f766970b803461bbc1a5b37bd
4
+ data.tar.gz: 5e78389663f0e6be3e2646252abb964482573e54c2640f867b9750867ef9dc64
5
5
  SHA512:
6
- metadata.gz: ba27165c663f82c25c026a83a062623e4cf694978ff9bbdcdce2745e37ff5ca205ba9080d96faa7bf3daa123f18a55bf72033b53d44c415ef6575e459cfc8eed
7
- data.tar.gz: 5fc0f8660d4d437ea127f6f5e5fdaacb56d245c212ce2f4d1ab0c87e76ab498f549aaae2e4490cc621fcfeb681494bb3033ee25b02114d9e3504dfa51aa9845b
6
+ metadata.gz: d116e2ebbb05af6c7fd2cdd472ca0b1099c2923d82e07a5315b0eebc0ac756097ffb78e0118a01fca35d502a5fb1b8e107ee02604bf3450206497e781235fead
7
+ data.tar.gz: 026b2ac9467cd20373e9372d383857466f0a2a72bbb3273edf038f42c555439a680ffabc742a5bb7987a7563c5cdadba6d4895574b3d0f1bdc09ca1f5db461ae
data/CHANGELOG.md ADDED
@@ -0,0 +1,59 @@
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.0] - 2026-11-17
10
+ No change to the public API or runtime behavior; the major bump is for the Ruby floor.
11
+
12
+ ### Changed
13
+ - **BREAKING:** Requires Ruby >= 3.4 (was >= 3.2). Development Ruby is 3.4.12.
14
+ - Version now lives in `NounProjectApi::VERSION` (`lib/noun_project_api/version.rb`).
15
+ - Gemspec follows current conventions: `add_dependency`, rubygems metadata URIs, and the packaged
16
+ files are now `lib/`, `README.md`, `CHANGELOG.md` and `LICENSE` (it listed files that did not exist).
17
+ - Development dependencies moved to the `Gemfile` and upgraded to their latest releases
18
+ (rspec 3.13, rubocop 1.92 with rubocop-rspec 3.10, faker 3.8, rake 13.4), bundled with Bundler 4.1.
19
+ - Specs modernized (`described_class`, `let`, spies, `Struct` in place of `OpenStruct`), with added
20
+ coverage for search caching, error responses and Marshal round-trip of cached icons.
21
+
22
+ ### Removed
23
+ - Travis CI config (CI runs on GitHub Actions).
24
+
25
+ ## [3.1.0] - 2020-07-10
26
+ ### Changed
27
+ - Changed is_published attribute to published
28
+ - rubocop update and fixes
29
+ - Switch to symbol based hash access
30
+ - Dropped semver gem
31
+ - Gem updates
32
+ - Add cache TTL support.
33
+ - Switched to Github actions
34
+
35
+ ## [3.0.0] - 2020-07-10
36
+ ### Changed
37
+ - Updated to Ruby 2.7.1
38
+ - Add cache support.
39
+
40
+ ## [2.0.1] - 2018-09-06
41
+ ### Changed
42
+ - Changed `IconRetriever` class' error class from `ArgumentError` to `ServiceError` when responses http code from Noun Project API are other than `200` **BREAKING CHANGE**
43
+
44
+ ## [2.0.0] - 2018-09-06
45
+ ### Added
46
+ - Added `CHANGELOG.md`
47
+ - Added `ServiceError` class to represent errors returned from Noun Project API with additional `code` and `body` attributes
48
+
49
+ ### Changed
50
+ - Changed `Retriever` class' error class from `ArgumentError` to `ServiceError` when responses http code from Noun Project API are other than `200` **BREAKING CHANGE**
51
+
52
+ ### Removed
53
+ - Removed CircleCI support
54
+ - Dropped Rubinius (rbx-2) support
55
+ - Dropped Ruby 1.9 support
56
+
57
+ ## [1.0.0] - 2016-06-16
58
+ ### Added
59
+ - 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)
@@ -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.0"
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.4
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tailor Engineering
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-06-28 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
@@ -16,14 +15,20 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '0'
18
+ version: '7.2'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '9'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
26
  - - ">="
25
27
  - !ruby/object:Gem::Version
26
- version: '0'
28
+ version: '7.2'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '9'
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: oauth
29
34
  requirement: !ruby/object:Gem::Requirement
@@ -38,69 +43,15 @@ dependencies:
38
43
  - - "~>"
39
44
  - !ruby/object:Gem::Version
40
45
  version: '1.1'
41
- - !ruby/object:Gem::Dependency
42
- name: faker
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.1'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.1'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '13.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '13.0'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '3.12'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.12'
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '1'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '1'
97
46
  description: A Gem to expose a wrapping API for The Noun Project API's
98
47
  email: sloths@tailorbrands.com
99
48
  executables: []
100
49
  extensions: []
101
50
  extra_rdoc_files: []
102
51
  files:
103
- - Rakefile
52
+ - CHANGELOG.md
53
+ - LICENSE
54
+ - README.md
104
55
  - lib/noun_project_api.rb
105
56
  - lib/noun_project_api/base_item.rb
106
57
  - lib/noun_project_api/collection.rb
@@ -112,22 +63,14 @@ files:
112
63
  - lib/noun_project_api/icons_retriever.rb
113
64
  - lib/noun_project_api/reporter.rb
114
65
  - lib/noun_project_api/retriever.rb
115
- - spec/lib/noun_project_api/base_item_spec.rb
116
- - spec/lib/noun_project_api/collection_retriever_spec.rb
117
- - spec/lib/noun_project_api/collection_spec.rb
118
- - spec/lib/noun_project_api/icon_retriever_spec.rb
119
- - spec/lib/noun_project_api/icon_spec.rb
120
- - spec/lib/noun_project_api/icons_retriever_spec.rb
121
- - spec/lib/noun_project_api/reporter_spec.rb
122
- - spec/lib/noun_project_api/retriever_spec.rb
123
- - spec/lib/noun_project_api_spec.rb
124
- - spec/spec_helper.rb
125
- - spec/support/fakes.rb
66
+ - lib/noun_project_api/version.rb
126
67
  homepage: https://github.com/TailorBrands/noun-project-api
127
68
  licenses:
128
69
  - MIT
129
- metadata: {}
130
- 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
131
74
  rdoc_options: []
132
75
  require_paths:
133
76
  - lib
@@ -135,26 +78,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
78
  requirements:
136
79
  - - ">="
137
80
  - !ruby/object:Gem::Version
138
- version: '3.2'
81
+ version: '3.4'
139
82
  required_rubygems_version: !ruby/object:Gem::Requirement
140
83
  requirements:
141
84
  - - ">="
142
85
  - !ruby/object:Gem::Version
143
86
  version: '0'
144
87
  requirements: []
145
- rubygems_version: 3.4.6
146
- signing_key:
88
+ rubygems_version: 3.6.9
147
89
  specification_version: 4
148
90
  summary: An API wrapper for The Noun Project API's
149
- test_files:
150
- - spec/lib/noun_project_api/base_item_spec.rb
151
- - spec/lib/noun_project_api/collection_retriever_spec.rb
152
- - spec/lib/noun_project_api/collection_spec.rb
153
- - spec/lib/noun_project_api/icon_retriever_spec.rb
154
- - spec/lib/noun_project_api/icon_spec.rb
155
- - spec/lib/noun_project_api/icons_retriever_spec.rb
156
- - spec/lib/noun_project_api/reporter_spec.rb
157
- - spec/lib/noun_project_api/retriever_spec.rb
158
- - spec/lib/noun_project_api_spec.rb
159
- - spec/spec_helper.rb
160
- - 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