noun-project-api 3.0.0 → 3.1.2
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/Rakefile +9 -7
- data/lib/noun_project_api/base_item.rb +30 -0
- data/lib/{noun-project-api → noun_project_api}/collection.rb +10 -8
- data/lib/noun_project_api/collection_retriever.rb +14 -0
- data/lib/{noun-project-api → noun_project_api}/connection.rb +3 -1
- data/lib/{noun-project-api → noun_project_api}/errors.rb +2 -0
- data/lib/{noun-project-api → noun_project_api}/icon.rb +9 -7
- data/lib/noun_project_api/icon_retriever.rb +14 -0
- data/lib/{noun-project-api → noun_project_api}/icons_retriever.rb +12 -9
- data/lib/{noun-project-api → noun_project_api}/reporter.rb +5 -3
- data/lib/{noun-project-api → noun_project_api}/retriever.rb +3 -1
- data/lib/noun_project_api.rb +38 -0
- data/spec/lib/{noun-project-api → noun_project_api}/base_item_spec.rb +2 -0
- data/spec/lib/{noun-project-api → noun_project_api}/collection_retriever_spec.rb +5 -3
- data/spec/lib/{noun-project-api → noun_project_api}/collection_spec.rb +7 -5
- data/spec/lib/{noun-project-api → noun_project_api}/icon_retriever_spec.rb +5 -3
- data/spec/lib/{noun-project-api → noun_project_api}/icon_spec.rb +5 -3
- data/spec/lib/{noun-project-api → noun_project_api}/icons_retriever_spec.rb +8 -6
- data/spec/lib/{noun-project-api → noun_project_api}/reporter_spec.rb +2 -2
- data/spec/lib/{noun-project-api → noun_project_api}/retriever_spec.rb +2 -0
- data/spec/lib/{nount_project_api_spec.rb → noun_project_api_spec.rb} +2 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/support/fakes.rb +14 -12
- metadata +64 -64
- data/lib/noun-project-api/base_item.rb +0 -26
- data/lib/noun-project-api/collection_retriever.rb +0 -12
- data/lib/noun-project-api/icon_retriever.rb +0 -12
- data/lib/noun-project-api.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57cd0c3184717040510457e1f00d4fc30d3bafe34bd66a79387a2f87b2369ff7
|
4
|
+
data.tar.gz: 93849ba2931e657c68a19570faacc58e9c17c810d625a2787c4f66d3e3e101cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90c317fb050381fa8a0cc54d613547628b3c24d35df57a081f56ab38fbcbc95b25d1da659460e85de2fb508354bb6ece6e9aa6b18a919f841ba06050ed7889ea
|
7
|
+
data.tar.gz: 73442039897caeebd346f85e832a0e9d13bf5422369688e77bb7d5d9bfe492af7eaeea90d3bbe44e4cd84d91d904ebcc50a156ba4b32c61c8e0353d5b7fd2585
|
data/Rakefile
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler"
|
2
4
|
Bundler::GemHelper.install_tasks
|
3
5
|
|
4
|
-
|
6
|
+
$LOAD_PATH.unshift "lib"
|
5
7
|
|
6
|
-
desc
|
7
|
-
task :
|
8
|
+
desc "Default: run unit tests."
|
9
|
+
task default: [:spec]
|
8
10
|
|
9
|
-
require
|
11
|
+
require "rspec/core/rake_task"
|
10
12
|
|
11
|
-
desc
|
13
|
+
desc "Run specs"
|
12
14
|
RSpec::Core::RakeTask.new do |t|
|
13
|
-
t.pattern =
|
15
|
+
t.pattern = "./spec/**/*_spec.rb"
|
14
16
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NounProjectApi
|
4
|
+
# A basis to Items returned by the noun project.
|
5
|
+
class BaseItem
|
6
|
+
attr_accessor :original_hash
|
7
|
+
ITEM_NAME = nil
|
8
|
+
|
9
|
+
def initialize(origin)
|
10
|
+
raise NotImplementedError, "Must use a subclass" if self.class::ITEM_NAME.nil?
|
11
|
+
|
12
|
+
origin = JSON.parse(origin, symbolize_names: true) if origin.is_a? String
|
13
|
+
if origin.key? self.class::ITEM_NAME
|
14
|
+
origin = origin.delete(
|
15
|
+
self.class::ITEM_NAME
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
@original_hash = origin
|
20
|
+
end
|
21
|
+
|
22
|
+
def id
|
23
|
+
original_hash[:id].to_i
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_json(*_args)
|
27
|
+
JSON.dump(to_hash)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,24 +1,26 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "noun_project_api/base_item"
|
2
4
|
|
3
5
|
module NounProjectApi
|
4
6
|
# A single Collection as an abstracted ruby object.
|
5
7
|
class Collection < BaseItem
|
6
|
-
ITEM_NAME =
|
8
|
+
ITEM_NAME = :collection
|
7
9
|
|
8
10
|
def author_id
|
9
|
-
original_hash[
|
11
|
+
original_hash[:author_id].to_i
|
10
12
|
end
|
11
13
|
|
12
14
|
def author_name
|
13
|
-
original_hash[
|
15
|
+
original_hash[:author][:name]
|
14
16
|
end
|
15
17
|
|
16
18
|
def icon_count
|
17
|
-
original_hash[
|
19
|
+
original_hash[:icon_count].to_i
|
18
20
|
end
|
19
21
|
|
20
|
-
def
|
21
|
-
original_hash[
|
22
|
+
def published?
|
23
|
+
original_hash[:is_published].to_i == 1
|
22
24
|
end
|
23
25
|
|
24
26
|
def to_hash
|
@@ -27,7 +29,7 @@ module NounProjectApi
|
|
27
29
|
author_id: author_id,
|
28
30
|
author_name: author_name,
|
29
31
|
icon_count: icon_count,
|
30
|
-
|
32
|
+
published: published?
|
31
33
|
}
|
32
34
|
end
|
33
35
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "noun_project_api/collection"
|
4
|
+
require "noun_project_api/retriever"
|
5
|
+
|
6
|
+
module NounProjectApi
|
7
|
+
# Retrieve a collection.
|
8
|
+
class CollectionRetriever < Retriever
|
9
|
+
API_PATH = "/collection/"
|
10
|
+
ITEM_CLASS = Collection
|
11
|
+
|
12
|
+
alias find_by_slug find
|
13
|
+
end
|
14
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module NounProjectApi
|
2
4
|
# Basic connection methods and setup.
|
3
5
|
module Connection
|
@@ -6,7 +8,7 @@ module NounProjectApi
|
|
6
8
|
def initialize(token, secret)
|
7
9
|
@token = token
|
8
10
|
@secret = secret
|
9
|
-
raise ArgumentError
|
11
|
+
raise ArgumentError, "Missing token or secret" unless @token && @secret
|
10
12
|
|
11
13
|
@access_token = OAuth::AccessToken.new(OAuth::Consumer.new(token, secret))
|
12
14
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "noun_project_api/base_item"
|
2
4
|
|
3
5
|
module NounProjectApi
|
4
6
|
# A single Icon as an abstracted ruby object.
|
@@ -7,23 +9,23 @@ module NounProjectApi
|
|
7
9
|
PREVIEW_SIZE_42 = 42
|
8
10
|
PREVIEW_SIZE_84 = 84
|
9
11
|
|
10
|
-
PUBLIC_DOMAIN_LICENSE = "public-domain"
|
12
|
+
PUBLIC_DOMAIN_LICENSE = "public-domain"
|
11
13
|
|
12
|
-
ITEM_NAME =
|
14
|
+
ITEM_NAME = :icon
|
13
15
|
|
14
16
|
def public_domain?
|
15
|
-
original_hash[
|
17
|
+
original_hash[:license_description] == PUBLIC_DOMAIN_LICENSE
|
16
18
|
end
|
17
19
|
|
18
20
|
def svg_url
|
19
|
-
original_hash[
|
21
|
+
original_hash[:icon_url]
|
20
22
|
end
|
21
23
|
|
22
24
|
def preview_url(size = PREVIEW_SIZE_200)
|
23
25
|
if size == PREVIEW_SIZE_200
|
24
|
-
original_hash[
|
26
|
+
original_hash[:preview_url]
|
25
27
|
else
|
26
|
-
original_hash["preview_url_#{size}"]
|
28
|
+
original_hash[:"preview_url_#{size}"]
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "noun_project_api/icon"
|
4
|
+
require "noun_project_api/retriever"
|
5
|
+
|
6
|
+
module NounProjectApi
|
7
|
+
# Retrieve an icon.
|
8
|
+
class IconRetriever < Retriever
|
9
|
+
API_PATH = "/icon/"
|
10
|
+
ITEM_CLASS = Icon
|
11
|
+
|
12
|
+
alias find_by_slug find
|
13
|
+
end
|
14
|
+
end
|
@@ -1,9 +1,11 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "noun_project_api/retriever"
|
2
4
|
|
3
5
|
module NounProjectApi
|
4
6
|
# Retrieve icons.
|
5
7
|
class IconsRetriever < Retriever
|
6
|
-
API_PATH = "/icons/"
|
8
|
+
API_PATH = "/icons/"
|
7
9
|
|
8
10
|
# Finds multiple icons based on the term
|
9
11
|
# * term - search term
|
@@ -12,9 +14,10 @@ module NounProjectApi
|
|
12
14
|
# * page - page number
|
13
15
|
def find(term, limit = nil, offset = nil, page = nil)
|
14
16
|
cache_key = Digest::MD5.hexdigest("#{term}+#{limit}+#{offset}+#{page}")
|
17
|
+
cache_ttl = NounProjectApi.configuration.cache_ttl
|
15
18
|
|
16
|
-
NounProjectApi.configuration.cache.fetch(cache_key) do
|
17
|
-
raise ArgumentError
|
19
|
+
NounProjectApi.configuration.cache.fetch(cache_key, expires_in: cache_ttl) do
|
20
|
+
raise ArgumentError, "Missing search term" unless term
|
18
21
|
|
19
22
|
search = OAuth::Helper.escape(term)
|
20
23
|
search += "?limit_to_public_domain=#{NounProjectApi.configuration.public_domain ? 1 : 0}"
|
@@ -24,13 +27,13 @@ module NounProjectApi
|
|
24
27
|
"offset" => offset,
|
25
28
|
"page" => page
|
26
29
|
}.reject { |_, v| v.nil? }
|
27
|
-
args.each { |k, v| search += "&#{k}=#{v}" }
|
30
|
+
args.each { |k, v| search += "&#{k}=#{v}" } unless args.empty?
|
28
31
|
|
29
32
|
result = access_token.get("#{API_BASE}#{API_PATH}#{search}")
|
30
|
-
raise ServiceError.new(result.code, result.body) unless
|
33
|
+
raise ServiceError.new(result.code, result.body) unless ["200", "404"].include? result.code
|
31
34
|
|
32
35
|
if result.code == "200"
|
33
|
-
JSON.parse(result.body)[
|
36
|
+
JSON.parse(result.body, symbolize_names: true)[:icons].map { |icon| Icon.new(icon) }
|
34
37
|
else
|
35
38
|
[]
|
36
39
|
end
|
@@ -47,7 +50,7 @@ module NounProjectApi
|
|
47
50
|
"offset" => offset,
|
48
51
|
"page" => page
|
49
52
|
}.reject { |_, v| v.nil? }
|
50
|
-
if args.
|
53
|
+
if !args.empty?
|
51
54
|
search = "?"
|
52
55
|
args.each { |k, v| search += "#{k}=#{v}&" }
|
53
56
|
else
|
@@ -57,7 +60,7 @@ module NounProjectApi
|
|
57
60
|
result = access_token.get("#{API_BASE}#{API_PATH}recent_uploads#{search}")
|
58
61
|
raise ServiceError.new(result.code, result.body) unless result.code == "200"
|
59
62
|
|
60
|
-
JSON.parse(result.body)[
|
63
|
+
JSON.parse(result.body, symbolize_names: true)[:recent_uploads].map { |icon| Icon.new(icon) }
|
61
64
|
end
|
62
65
|
end
|
63
66
|
end
|
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module NounProjectApi
|
2
4
|
# Main class to hold reporting actions back to the Noun Project.
|
3
5
|
class Reporter
|
4
6
|
include Connection
|
5
7
|
|
6
|
-
API_PATH = "/notify/publish"
|
8
|
+
API_PATH = "/notify/publish"
|
7
9
|
|
8
10
|
def report_used(ids)
|
9
|
-
ids = [ids] if ids.is_a?(String) || ids.is_a?(
|
10
|
-
raise ArgumentError
|
11
|
+
ids = [ids] if ids.is_a?(String) || ids.is_a?(Integer)
|
12
|
+
raise ArgumentError, "Missing ids" if ids.nil? || ids.empty?
|
11
13
|
|
12
14
|
result = access_token.post(
|
13
15
|
"#{API_BASE}#{API_PATH}",
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module NounProjectApi
|
2
4
|
# A base class for different retriever classes.
|
3
5
|
class Retriever
|
@@ -5,7 +7,7 @@ module NounProjectApi
|
|
5
7
|
|
6
8
|
# Find an item based on it's id.
|
7
9
|
def find(id)
|
8
|
-
raise ArgumentError
|
10
|
+
raise ArgumentError, "Missing id/slug" unless id
|
9
11
|
|
10
12
|
result = access_token.get("#{API_BASE}#{self.class::API_PATH}#{id}")
|
11
13
|
raise ServiceError.new(result.code, result.body) unless result.code == "200"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "oauth"
|
4
|
+
require "active_support"
|
5
|
+
require "json"
|
6
|
+
require "noun_project_api/errors"
|
7
|
+
require "noun_project_api/connection"
|
8
|
+
require "noun_project_api/icon_retriever"
|
9
|
+
require "noun_project_api/reporter"
|
10
|
+
require "noun_project_api/icons_retriever"
|
11
|
+
require "noun_project_api/icon"
|
12
|
+
require "noun_project_api/collection_retriever"
|
13
|
+
require "noun_project_api/collection"
|
14
|
+
|
15
|
+
# Top level name space for the entire Gem.
|
16
|
+
module NounProjectApi
|
17
|
+
API_BASE = "http://api.thenounproject.com"
|
18
|
+
|
19
|
+
def self.configuration
|
20
|
+
@configuration ||= Configuration.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.configure
|
24
|
+
self.configuration ||= Configuration.new
|
25
|
+
yield(configuration) if block_given?
|
26
|
+
end
|
27
|
+
|
28
|
+
# Main configuration class.
|
29
|
+
class Configuration
|
30
|
+
attr_accessor :public_domain, :cache, :cache_ttl
|
31
|
+
|
32
|
+
def initialize
|
33
|
+
@public_domain = false
|
34
|
+
@cache = ActiveSupport::Cache::NullStore.new
|
35
|
+
@cache_ttl = 604800 # Week in seconds
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
require "ostruct"
|
3
5
|
|
4
6
|
RSpec.describe NounProjectApi::CollectionRetriever do
|
5
7
|
before :each do
|
6
8
|
@collection = NounProjectApi::CollectionRetriever.new(Faker::Internet.password(min_length: 16), Faker::Internet.password(min_length: 16))
|
7
|
-
@valid_hash = JSON.parse(Fakes::Results::COLLECTION_VALID)
|
9
|
+
@valid_hash = JSON.parse(Fakes::Results::COLLECTION_VALID, symbolize_names: true)
|
8
10
|
@valid_response = OpenStruct.new(
|
9
11
|
body: Fakes::Results::COLLECTION_VALID,
|
10
12
|
code: "200"
|
@@ -32,7 +34,7 @@ RSpec.describe NounProjectApi::CollectionRetriever do
|
|
32
34
|
|
33
35
|
result = @collection.find(id)
|
34
36
|
expect(result).to be_a(NounProjectApi::Collection)
|
35
|
-
expect(result.original_hash).to eq(@valid_hash[
|
37
|
+
expect(result.original_hash).to eq(@valid_hash[:collection])
|
36
38
|
end
|
37
39
|
|
38
40
|
it "raises an error with a missing id" do
|
@@ -66,7 +68,7 @@ RSpec.describe NounProjectApi::CollectionRetriever do
|
|
66
68
|
|
67
69
|
result = @collection.find(slug)
|
68
70
|
expect(result).to be_a(NounProjectApi::Collection)
|
69
|
-
expect(result.original_hash).to eq(@valid_hash[
|
71
|
+
expect(result.original_hash).to eq(@valid_hash[:collection])
|
70
72
|
end
|
71
73
|
|
72
74
|
it "raises an error with a missing slug" do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
require "ostruct"
|
3
5
|
|
@@ -27,7 +29,7 @@ RSpec.describe NounProjectApi::CollectionRetriever do
|
|
27
29
|
end
|
28
30
|
|
29
31
|
it "id as number" do
|
30
|
-
expect(@valid_collection.id).to be_a(
|
32
|
+
expect(@valid_collection.id).to be_a(Integer)
|
31
33
|
expect(@valid_collection.id).to eq(@json["collection"]["id"].to_i)
|
32
34
|
end
|
33
35
|
|
@@ -44,17 +46,17 @@ RSpec.describe NounProjectApi::CollectionRetriever do
|
|
44
46
|
end
|
45
47
|
|
46
48
|
it "is published" do
|
47
|
-
expect(@valid_collection.
|
49
|
+
expect(@valid_collection.published?).to eq(@json["collection"]["is_published"].to_i == 1)
|
48
50
|
end
|
49
51
|
|
50
52
|
it "builds a simple hash" do
|
51
|
-
expect(@valid_collection.to_hash).to eq(
|
53
|
+
expect(@valid_collection.to_hash).to eq(
|
52
54
|
id: @valid_collection.id,
|
53
55
|
author_id: @valid_collection.author_id,
|
54
56
|
author_name: @valid_collection.author_name,
|
55
57
|
icon_count: @valid_collection.icon_count,
|
56
|
-
|
57
|
-
|
58
|
+
published: @valid_collection.published?
|
59
|
+
)
|
58
60
|
end
|
59
61
|
|
60
62
|
it "json formats the hash" do
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
require "ostruct"
|
3
5
|
|
4
6
|
RSpec.describe NounProjectApi::IconRetriever do
|
5
7
|
before :each do
|
6
8
|
@icon = NounProjectApi::IconRetriever.new(Faker::Internet.password(min_length: 16), Faker::Internet.password(min_length: 16))
|
7
|
-
@valid_hash = JSON.parse(Fakes::Results::ICON_VALID)
|
9
|
+
@valid_hash = JSON.parse(Fakes::Results::ICON_VALID, symbolize_names: true)
|
8
10
|
@valid_response = OpenStruct.new(
|
9
11
|
body: Fakes::Results::ICON_VALID,
|
10
12
|
code: "200"
|
@@ -32,7 +34,7 @@ RSpec.describe NounProjectApi::IconRetriever do
|
|
32
34
|
|
33
35
|
result = @icon.find(id)
|
34
36
|
expect(result).to be_a(NounProjectApi::Icon)
|
35
|
-
expect(result.original_hash).to eq(@valid_hash[
|
37
|
+
expect(result.original_hash).to eq(@valid_hash[:icon])
|
36
38
|
end
|
37
39
|
|
38
40
|
it "raises an error with a missing id" do
|
@@ -66,7 +68,7 @@ RSpec.describe NounProjectApi::IconRetriever do
|
|
66
68
|
|
67
69
|
result = @icon.find(slug)
|
68
70
|
expect(result).to be_a(NounProjectApi::Icon)
|
69
|
-
expect(result.original_hash).to eq(@valid_hash[
|
71
|
+
expect(result.original_hash).to eq(@valid_hash[:icon])
|
70
72
|
end
|
71
73
|
|
72
74
|
it "raises an error with a missing slug" do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
require "ostruct"
|
3
5
|
|
@@ -57,17 +59,17 @@ RSpec.describe NounProjectApi::IconRetriever do
|
|
57
59
|
end
|
58
60
|
|
59
61
|
it "id as number" do
|
60
|
-
expect(@valid_icon.id).to be_a(
|
62
|
+
expect(@valid_icon.id).to be_a(Integer)
|
61
63
|
expect(@valid_icon.id).to eq(@json["icon"]["id"].to_i)
|
62
64
|
end
|
63
65
|
|
64
66
|
it "builds a simple hash" do
|
65
|
-
expect(@valid_icon.to_hash).to eq(
|
67
|
+
expect(@valid_icon.to_hash).to eq(
|
66
68
|
id: @valid_icon.id,
|
67
69
|
preview_url_200: @valid_icon.preview_url(NounProjectApi::Icon::PREVIEW_SIZE_200),
|
68
70
|
preview_url_84: @valid_icon.preview_url(NounProjectApi::Icon::PREVIEW_SIZE_84),
|
69
71
|
preview_url_42: @valid_icon.preview_url(NounProjectApi::Icon::PREVIEW_SIZE_42)
|
70
|
-
|
72
|
+
)
|
71
73
|
end
|
72
74
|
|
73
75
|
it "json formats the hash" do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
RSpec.describe NounProjectApi::IconsRetriever do
|
@@ -64,11 +66,11 @@ RSpec.describe NounProjectApi::IconsRetriever do
|
|
64
66
|
code: "200"
|
65
67
|
)
|
66
68
|
|
67
|
-
term =
|
69
|
+
term = 'some search with ",] bad chars'
|
68
70
|
expect(@icons.access_token).to receive(
|
69
71
|
:get
|
70
72
|
).with(
|
71
|
-
"#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{OAuth::Helper
|
73
|
+
"#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{OAuth::Helper.escape(term)}?limit_to_public_domain=0"
|
72
74
|
).and_return(
|
73
75
|
valid_response
|
74
76
|
)
|
@@ -91,7 +93,7 @@ RSpec.describe NounProjectApi::IconsRetriever do
|
|
91
93
|
expect(@icons.access_token).to receive(
|
92
94
|
:get
|
93
95
|
).with(
|
94
|
-
"#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{OAuth::Helper
|
96
|
+
"#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{OAuth::Helper.escape(term)}?limit_to_public_domain=0"
|
95
97
|
).and_return(
|
96
98
|
valid_response
|
97
99
|
)
|
@@ -114,7 +116,7 @@ RSpec.describe NounProjectApi::IconsRetriever do
|
|
114
116
|
expect(@icons.access_token).to receive(
|
115
117
|
:get
|
116
118
|
).with(
|
117
|
-
"#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{OAuth::Helper
|
119
|
+
"#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{OAuth::Helper.escape(term)}?limit_to_public_domain=1"
|
118
120
|
).and_return(
|
119
121
|
valid_response
|
120
122
|
)
|
@@ -139,7 +141,7 @@ RSpec.describe NounProjectApi::IconsRetriever do
|
|
139
141
|
expect(@icons.access_token).to receive(
|
140
142
|
:get
|
141
143
|
).with(
|
142
|
-
"#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{OAuth::Helper
|
144
|
+
"#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{OAuth::Helper.escape(term)}?limit_to_public_domain=0&limit=#{limit}"
|
143
145
|
).and_return(
|
144
146
|
valid_response
|
145
147
|
)
|
@@ -160,7 +162,7 @@ RSpec.describe NounProjectApi::IconsRetriever do
|
|
160
162
|
expect(@icons.access_token).to receive(
|
161
163
|
:get
|
162
164
|
).with(
|
163
|
-
"#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{OAuth::Helper
|
165
|
+
"#{NounProjectApi::API_BASE}#{NounProjectApi::IconsRetriever::API_PATH}#{OAuth::Helper.escape(term)}?limit_to_public_domain=0"
|
164
166
|
).and_return(
|
165
167
|
missing_response
|
166
168
|
)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
RSpec.describe NounProjectApi::Reporter do
|
@@ -69,8 +71,6 @@ RSpec.describe NounProjectApi::Reporter do
|
|
69
71
|
expect(result).to be true
|
70
72
|
end
|
71
73
|
|
72
|
-
|
73
|
-
|
74
74
|
it "reports multiple ids" do
|
75
75
|
valid_response = OpenStruct.new(
|
76
76
|
body: Fakes::Results::REPORTED_ONE,
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/fakes.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Fakes
|
2
4
|
module Results
|
3
|
-
ICON_VALID = '
|
5
|
+
ICON_VALID = ""'
|
4
6
|
{
|
5
7
|
"icon": {
|
6
8
|
"term_slug": "beauty-salon",
|
@@ -83,9 +85,9 @@ module Fakes
|
|
83
85
|
"term_id": 645
|
84
86
|
}
|
85
87
|
}
|
86
|
-
'
|
88
|
+
'""
|
87
89
|
|
88
|
-
ICONS_RECENT_VALID = '
|
90
|
+
ICONS_RECENT_VALID = ""'
|
89
91
|
{
|
90
92
|
"recent_uploads": [
|
91
93
|
{
|
@@ -172,9 +174,9 @@ module Fakes
|
|
172
174
|
}
|
173
175
|
],
|
174
176
|
"generated_at": "Thu, 18 Sep 2014 18:09:34 GMT"
|
175
|
-
}'
|
177
|
+
}'""
|
176
178
|
|
177
|
-
ICONS_VALID = '
|
179
|
+
ICONS_VALID = ""'
|
178
180
|
{
|
179
181
|
"generated_at": "Thu, 18 Sep 2014 17:48:10 GMT",
|
180
182
|
"icons": [
|
@@ -295,21 +297,21 @@ module Fakes
|
|
295
297
|
"term_id": 857
|
296
298
|
}
|
297
299
|
]
|
298
|
-
}'
|
300
|
+
}'""
|
299
301
|
|
300
|
-
REPORTED_ONE = '
|
302
|
+
REPORTED_ONE = ""'
|
301
303
|
{
|
302
304
|
"licenses_consumed": 1,
|
303
305
|
"result": "success"
|
304
|
-
}'
|
306
|
+
}'""
|
305
307
|
|
306
|
-
REPORTED_THREE = '
|
308
|
+
REPORTED_THREE = ""'
|
307
309
|
{
|
308
310
|
"licenses_consumed": 1,
|
309
311
|
"result": "success"
|
310
|
-
}'
|
312
|
+
}'""
|
311
313
|
|
312
|
-
COLLECTION_VALID = '
|
314
|
+
COLLECTION_VALID = ""'
|
313
315
|
{
|
314
316
|
"collection": {
|
315
317
|
"author": {
|
@@ -388,6 +390,6 @@ module Fakes
|
|
388
390
|
"template": "24"
|
389
391
|
}
|
390
392
|
}
|
391
|
-
'
|
393
|
+
'""
|
392
394
|
end
|
393
395
|
end
|
metadata
CHANGED
@@ -1,99 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noun-project-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- Tailor Engineering
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: oauth
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '0.5'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '0.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: faker
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '13
|
47
|
+
version: '2.13'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '13
|
54
|
+
version: '2.13'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: pry
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0.13'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0.13'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '13.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '13.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '3.9'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '3.9'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rspec_junit_formatter
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,53 +109,53 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0.4'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: rubocop
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - '='
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 0.79.0
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - '='
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: 0.79.0
|
125
125
|
description: A Gem to expose a wrapping API for The Noun Project API's
|
126
|
-
email:
|
126
|
+
email: sloths@tailorbrands.com
|
127
127
|
executables: []
|
128
128
|
extensions: []
|
129
129
|
extra_rdoc_files: []
|
130
130
|
files:
|
131
131
|
- Rakefile
|
132
|
-
- lib/
|
133
|
-
- lib/
|
134
|
-
- lib/
|
135
|
-
- lib/
|
136
|
-
- lib/
|
137
|
-
- lib/
|
138
|
-
- lib/
|
139
|
-
- lib/
|
140
|
-
- lib/
|
141
|
-
- lib/
|
142
|
-
- lib/
|
143
|
-
- spec/lib/
|
144
|
-
- spec/lib/
|
145
|
-
- spec/lib/
|
146
|
-
- spec/lib/
|
147
|
-
- spec/lib/
|
148
|
-
- spec/lib/
|
149
|
-
- spec/lib/
|
150
|
-
- spec/lib/
|
151
|
-
- spec/lib/
|
132
|
+
- lib/noun_project_api.rb
|
133
|
+
- lib/noun_project_api/base_item.rb
|
134
|
+
- lib/noun_project_api/collection.rb
|
135
|
+
- lib/noun_project_api/collection_retriever.rb
|
136
|
+
- lib/noun_project_api/connection.rb
|
137
|
+
- lib/noun_project_api/errors.rb
|
138
|
+
- lib/noun_project_api/icon.rb
|
139
|
+
- lib/noun_project_api/icon_retriever.rb
|
140
|
+
- lib/noun_project_api/icons_retriever.rb
|
141
|
+
- lib/noun_project_api/reporter.rb
|
142
|
+
- lib/noun_project_api/retriever.rb
|
143
|
+
- spec/lib/noun_project_api/base_item_spec.rb
|
144
|
+
- spec/lib/noun_project_api/collection_retriever_spec.rb
|
145
|
+
- spec/lib/noun_project_api/collection_spec.rb
|
146
|
+
- spec/lib/noun_project_api/icon_retriever_spec.rb
|
147
|
+
- spec/lib/noun_project_api/icon_spec.rb
|
148
|
+
- spec/lib/noun_project_api/icons_retriever_spec.rb
|
149
|
+
- spec/lib/noun_project_api/reporter_spec.rb
|
150
|
+
- spec/lib/noun_project_api/retriever_spec.rb
|
151
|
+
- spec/lib/noun_project_api_spec.rb
|
152
152
|
- spec/spec_helper.rb
|
153
153
|
- spec/support/fakes.rb
|
154
154
|
homepage: https://github.com/TailorBrands/noun-project-api
|
155
155
|
licenses:
|
156
156
|
- MIT
|
157
157
|
metadata: {}
|
158
|
-
post_install_message:
|
158
|
+
post_install_message:
|
159
159
|
rdoc_options: []
|
160
160
|
require_paths:
|
161
161
|
- lib
|
@@ -170,19 +170,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
170
|
- !ruby/object:Gem::Version
|
171
171
|
version: '0'
|
172
172
|
requirements: []
|
173
|
-
rubygems_version: 3.
|
174
|
-
signing_key:
|
173
|
+
rubygems_version: 3.3.7
|
174
|
+
signing_key:
|
175
175
|
specification_version: 4
|
176
176
|
summary: An API wrapper for The Noun Project API's
|
177
177
|
test_files:
|
178
|
+
- spec/lib/noun_project_api/base_item_spec.rb
|
179
|
+
- spec/lib/noun_project_api/collection_retriever_spec.rb
|
180
|
+
- spec/lib/noun_project_api/collection_spec.rb
|
181
|
+
- spec/lib/noun_project_api/icon_retriever_spec.rb
|
182
|
+
- spec/lib/noun_project_api/icon_spec.rb
|
183
|
+
- spec/lib/noun_project_api/icons_retriever_spec.rb
|
184
|
+
- spec/lib/noun_project_api/reporter_spec.rb
|
185
|
+
- spec/lib/noun_project_api/retriever_spec.rb
|
186
|
+
- spec/lib/noun_project_api_spec.rb
|
178
187
|
- spec/spec_helper.rb
|
179
188
|
- spec/support/fakes.rb
|
180
|
-
- spec/lib/nount_project_api_spec.rb
|
181
|
-
- spec/lib/noun-project-api/collection_spec.rb
|
182
|
-
- spec/lib/noun-project-api/icon_spec.rb
|
183
|
-
- spec/lib/noun-project-api/base_item_spec.rb
|
184
|
-
- spec/lib/noun-project-api/collection_retriever_spec.rb
|
185
|
-
- spec/lib/noun-project-api/retriever_spec.rb
|
186
|
-
- spec/lib/noun-project-api/icon_retriever_spec.rb
|
187
|
-
- spec/lib/noun-project-api/reporter_spec.rb
|
188
|
-
- spec/lib/noun-project-api/icons_retriever_spec.rb
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module NounProjectApi
|
2
|
-
# A basis to Items returned by the noun project.
|
3
|
-
class BaseItem
|
4
|
-
attr_accessor :original_hash
|
5
|
-
ITEM_NAME = nil
|
6
|
-
|
7
|
-
def initialize(origin)
|
8
|
-
raise NotImplementedError.new("Must use a subclass") if self.class::ITEM_NAME.nil?
|
9
|
-
|
10
|
-
origin = JSON.parse(origin) if origin.is_a? String
|
11
|
-
origin = origin.delete(
|
12
|
-
self.class::ITEM_NAME
|
13
|
-
) if origin.key? self.class::ITEM_NAME
|
14
|
-
|
15
|
-
@original_hash = origin
|
16
|
-
end
|
17
|
-
|
18
|
-
def id
|
19
|
-
original_hash["id"].to_i
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_json
|
23
|
-
JSON.dump(to_hash)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require "noun-project-api/collection"
|
2
|
-
require "noun-project-api/retriever"
|
3
|
-
|
4
|
-
module NounProjectApi
|
5
|
-
# Retrieve a collection.
|
6
|
-
class CollectionRetriever < Retriever
|
7
|
-
API_PATH = "/collection/".freeze
|
8
|
-
ITEM_CLASS = Collection
|
9
|
-
|
10
|
-
alias_method :find_by_slug, :find
|
11
|
-
end
|
12
|
-
end
|
data/lib/noun-project-api.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require "oauth"
|
2
|
-
require "active_support"
|
3
|
-
require "json"
|
4
|
-
require "noun-project-api/errors"
|
5
|
-
require "noun-project-api/connection"
|
6
|
-
require "noun-project-api/icon_retriever"
|
7
|
-
require "noun-project-api/reporter"
|
8
|
-
require "noun-project-api/icons_retriever"
|
9
|
-
require "noun-project-api/icon"
|
10
|
-
require "noun-project-api/collection_retriever"
|
11
|
-
require "noun-project-api/collection"
|
12
|
-
|
13
|
-
# Top level name space for the entire Gem.
|
14
|
-
module NounProjectApi
|
15
|
-
API_BASE = "http://api.thenounproject.com".freeze
|
16
|
-
|
17
|
-
def self.configuration
|
18
|
-
@configuration ||= Configuration.new
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.configure
|
22
|
-
self.configuration ||= Configuration.new
|
23
|
-
yield(configuration) if block_given?
|
24
|
-
end
|
25
|
-
|
26
|
-
# Main configuration class.
|
27
|
-
class Configuration
|
28
|
-
attr_accessor :public_domain, :cache
|
29
|
-
|
30
|
-
def initialize
|
31
|
-
@public_domain = false
|
32
|
-
@cache = ActiveSupport::Cache::NullStore.new
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|