noun-project-api 4.0.6 → 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 +13 -88
- 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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: abb76e3c819b291cea5d99748c2dc5f8f1ae460f766970b803461bbc1a5b37bd
|
|
4
|
+
data.tar.gz: 5e78389663f0e6be3e2646252abb964482573e54c2640f867b9750867ef9dc64
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
+
[](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
|
|
data/lib/noun_project_api.rb
CHANGED
|
@@ -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
|
+
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:
|
|
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
|
-
-
|
|
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
|
-
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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
|