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.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +9 -7
  3. data/lib/noun_project_api/base_item.rb +30 -0
  4. data/lib/{noun-project-api → noun_project_api}/collection.rb +10 -8
  5. data/lib/noun_project_api/collection_retriever.rb +14 -0
  6. data/lib/{noun-project-api → noun_project_api}/connection.rb +3 -1
  7. data/lib/{noun-project-api → noun_project_api}/errors.rb +2 -0
  8. data/lib/{noun-project-api → noun_project_api}/icon.rb +9 -7
  9. data/lib/noun_project_api/icon_retriever.rb +14 -0
  10. data/lib/{noun-project-api → noun_project_api}/icons_retriever.rb +12 -9
  11. data/lib/{noun-project-api → noun_project_api}/reporter.rb +5 -3
  12. data/lib/{noun-project-api → noun_project_api}/retriever.rb +3 -1
  13. data/lib/noun_project_api.rb +38 -0
  14. data/spec/lib/{noun-project-api → noun_project_api}/base_item_spec.rb +2 -0
  15. data/spec/lib/{noun-project-api → noun_project_api}/collection_retriever_spec.rb +5 -3
  16. data/spec/lib/{noun-project-api → noun_project_api}/collection_spec.rb +7 -5
  17. data/spec/lib/{noun-project-api → noun_project_api}/icon_retriever_spec.rb +5 -3
  18. data/spec/lib/{noun-project-api → noun_project_api}/icon_spec.rb +5 -3
  19. data/spec/lib/{noun-project-api → noun_project_api}/icons_retriever_spec.rb +8 -6
  20. data/spec/lib/{noun-project-api → noun_project_api}/reporter_spec.rb +2 -2
  21. data/spec/lib/{noun-project-api → noun_project_api}/retriever_spec.rb +2 -0
  22. data/spec/lib/{nount_project_api_spec.rb → noun_project_api_spec.rb} +2 -0
  23. data/spec/spec_helper.rb +3 -1
  24. data/spec/support/fakes.rb +14 -12
  25. metadata +64 -64
  26. data/lib/noun-project-api/base_item.rb +0 -26
  27. data/lib/noun-project-api/collection_retriever.rb +0 -12
  28. data/lib/noun-project-api/icon_retriever.rb +0 -12
  29. data/lib/noun-project-api.rb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc6c2457656761dd7e1bed16e52f00c5558a4f632a354f3fa7c626b90664b09b
4
- data.tar.gz: 184f196a2a7d1da39cc8988d0f7384374220a12a66cb495c06d52a53a3ee74ae
3
+ metadata.gz: 57cd0c3184717040510457e1f00d4fc30d3bafe34bd66a79387a2f87b2369ff7
4
+ data.tar.gz: 93849ba2931e657c68a19570faacc58e9c17c810d625a2787c4f66d3e3e101cb
5
5
  SHA512:
6
- metadata.gz: cf73f5f81a56f940567d2bff8b9dbeb0631d9e7f32f973bf5a29a2f541356420e5651a3c2d48705cd6823890a18d9f71ca2b45c4ad709fe80fad72c8ae41e473
7
- data.tar.gz: ae830b9869b6b10dea4b2287d511f7274692b6875776074d9c46eb5a706f0f63e984088eccb07b938087bbe943904ef4cc68762b74eee195db6c883985245bcf
6
+ metadata.gz: 90c317fb050381fa8a0cc54d613547628b3c24d35df57a081f56ab38fbcbc95b25d1da659460e85de2fb508354bb6ece6e9aa6b18a919f841ba06050ed7889ea
7
+ data.tar.gz: 73442039897caeebd346f85e832a0e9d13bf5422369688e77bb7d5d9bfe492af7eaeea90d3bbe44e4cd84d91d904ebcc50a156ba4b32c61c8e0353d5b7fd2585
data/Rakefile CHANGED
@@ -1,14 +1,16 @@
1
- require 'bundler'
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler"
2
4
  Bundler::GemHelper.install_tasks
3
5
 
4
- $:.unshift 'lib'
6
+ $LOAD_PATH.unshift "lib"
5
7
 
6
- desc 'Default: run unit tests.'
7
- task :default => [:spec]
8
+ desc "Default: run unit tests."
9
+ task default: [:spec]
8
10
 
9
- require 'rspec/core/rake_task'
11
+ require "rspec/core/rake_task"
10
12
 
11
- desc 'Run specs'
13
+ desc "Run specs"
12
14
  RSpec::Core::RakeTask.new do |t|
13
- t.pattern = './spec/**/*_spec.rb'
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
- require "noun-project-api/base_item"
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 = "collection".freeze
8
+ ITEM_NAME = :collection
7
9
 
8
10
  def author_id
9
- original_hash["author_id"].to_i
11
+ original_hash[:author_id].to_i
10
12
  end
11
13
 
12
14
  def author_name
13
- original_hash["author"]["name"]
15
+ original_hash[:author][:name]
14
16
  end
15
17
 
16
18
  def icon_count
17
- original_hash["icon_count"].to_i
19
+ original_hash[:icon_count].to_i
18
20
  end
19
21
 
20
- def is_published?
21
- original_hash["is_published"].to_i == 1
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
- is_published: is_published?
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.new("Missing token or secret") unless @token && @secret
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module NounProjectApi
2
4
  class ServiceError < StandardError
3
5
  attr_reader :status, :body
@@ -1,4 +1,6 @@
1
- require "noun-project-api/base_item"
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".freeze
12
+ PUBLIC_DOMAIN_LICENSE = "public-domain"
11
13
 
12
- ITEM_NAME = "icon".freeze
14
+ ITEM_NAME = :icon
13
15
 
14
16
  def public_domain?
15
- original_hash["license_description"] == PUBLIC_DOMAIN_LICENSE
17
+ original_hash[:license_description] == PUBLIC_DOMAIN_LICENSE
16
18
  end
17
19
 
18
20
  def svg_url
19
- original_hash["icon_url"]
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["preview_url"]
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
- require "noun-project-api/retriever"
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/".freeze
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.new("Missing search term") unless term
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}" } if args.size > 0
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 %w(200 404).include? result.code
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)["icons"].map { |icon| Icon.new(icon) }
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.size > 0
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)["recent_uploads"].map { |icon| Icon.new(icon) }
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".freeze
8
+ API_PATH = "/notify/publish"
7
9
 
8
10
  def report_used(ids)
9
- ids = [ids] if ids.is_a?(String) || ids.is_a?(Fixnum)
10
- raise ArgumentError.new("Missing ids") if ids.nil? || ids.empty?
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.new("Missing id/slug") unless id
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
  require "ostruct"
3
5
 
@@ -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["collection"])
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["collection"])
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(Fixnum)
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.is_published?).to eq(@json["collection"]["is_published"].to_i == 1)
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
- is_published: @valid_collection.is_published?
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["icon"])
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["icon"])
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(Fixnum)
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 = "some search with \",] bad chars"
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::escape(term)}?limit_to_public_domain=0"
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::escape(term)}?limit_to_public_domain=0"
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::escape(term)}?limit_to_public_domain=1"
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::escape(term)}?limit_to_public_domain=0&limit=#{limit}"
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::escape(term)}?limit_to_public_domain=0"
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,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  RSpec.describe NounProjectApi::Retriever do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  RSpec.describe NounProjectApi do
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/setup"
2
- require "noun-project-api"
4
+ require "noun_project_api"
3
5
  require "pry"
4
6
  require "faker"
5
7
  require "json"
@@ -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.0.0
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
- - Nadav Shatz
8
- autorequire:
7
+ - Tailor Engineering
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-07 00:00:00.000000000 Z
11
+ date: 2022-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: oauth
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.5'
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.5'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: activesupport
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: rake
42
+ name: faker
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '13.0'
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.0'
54
+ version: '2.13'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.9'
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: '3.9'
68
+ version: '0.13'
69
69
  - !ruby/object:Gem::Dependency
70
- name: faker
70
+ name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '2.13'
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: '2.13'
82
+ version: '13.0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: semver
84
+ name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.0'
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: '1.0'
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: pry
112
+ name: rubocop
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: '0.13'
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: '0.13'
124
+ version: 0.79.0
125
125
  description: A Gem to expose a wrapping API for The Noun Project API's
126
- email: nadav@tailorbrands.com
126
+ email: sloths@tailorbrands.com
127
127
  executables: []
128
128
  extensions: []
129
129
  extra_rdoc_files: []
130
130
  files:
131
131
  - Rakefile
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/nount_project_api_spec.rb
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.1.2
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
@@ -1,12 +0,0 @@
1
- require "noun-project-api/icon"
2
- require "noun-project-api/retriever"
3
-
4
- module NounProjectApi
5
- # Retrieve an icon.
6
- class IconRetriever < Retriever
7
- API_PATH = "/icon/".freeze
8
- ITEM_CLASS = Icon
9
-
10
- alias_method :find_by_slug, :find
11
- end
12
- end
@@ -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