noun-project-api 2.0.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) 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/icons_retriever.rb +66 -0
  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 +6 -4
  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 +6 -4
  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 +9 -7
  20. data/spec/lib/{noun-project-api → noun_project_api}/reporter_spec.rb +8 -8
  21. data/spec/lib/{noun-project-api → noun_project_api}/retriever_spec.rb +6 -4
  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 +65 -52
  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/icons_retriever.rb +0 -59
  30. data/lib/noun-project-api.rb +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94eaa51b84658f3763af7b3fe27e9f3f2f3b2666be78a2e580f0b2b569fcc10c
4
- data.tar.gz: f5cc891b28b004f1680f4176725775a02d616d720423357d36d3c5105a49e0ce
3
+ metadata.gz: d70a4e859c4f5df70a20d14388aaa8ff844e152a1a65ab0db7f8931d37a59078
4
+ data.tar.gz: e00a93508c63d34333c095af7ab6fb83163852c890a8d0205a7d77f58c2c1a8e
5
5
  SHA512:
6
- metadata.gz: fa6d50bafc00705171eec159e1290719299b5422ea956e1d8c8681365e6654fb444419e938de2ce00b80f50dc9142bc0fe4e0d146557bd89aa4ce728719886f2
7
- data.tar.gz: a3830940fe3886f39575ee050503ee8884062f23bc7c6ed34b43aa565d67d437fe320f3c4f3c1cb4bf4902b4b4a18a1ab3df52e87261d83271658044821bcab6
6
+ metadata.gz: 5aaf5a101160a9ec69a7f015b0718c6290c393f937e99c67662f79557926df079661803c39e78e24725754d05fb5c5d6eb4a8ba64372e69c28f523aabc4c5e47
7
+ data.tar.gz: 7aa5cd4a716a75bdde86e231c8979820aeadc3a8b0d78d8a73932170abb35a6145d7c7be143fe8232f8edfe8449e5fe22350e743c26e3ae2d001832a25d66dce
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
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "noun_project_api/retriever"
4
+
5
+ module NounProjectApi
6
+ # Retrieve icons.
7
+ class IconsRetriever < Retriever
8
+ API_PATH = "/icons/"
9
+
10
+ # Finds multiple icons based on the term
11
+ # * term - search term
12
+ # * limit - limit the amount of results
13
+ # * offset - offset the results
14
+ # * page - page number
15
+ def find(term, limit = nil, offset = nil, page = nil)
16
+ cache_key = Digest::MD5.hexdigest("#{term}+#{limit}+#{offset}+#{page}")
17
+ cache_ttl = NounProjectApi.configuration.cache_ttl
18
+
19
+ NounProjectApi.configuration.cache.fetch(cache_key, expires_in: cache_ttl) do
20
+ raise ArgumentError, "Missing search term" unless term
21
+
22
+ search = OAuth::Helper.escape(term)
23
+ search += "?limit_to_public_domain=#{NounProjectApi.configuration.public_domain ? 1 : 0}"
24
+
25
+ args = {
26
+ "limit" => limit,
27
+ "offset" => offset,
28
+ "page" => page
29
+ }.reject { |_, v| v.nil? }
30
+ args.each { |k, v| search += "&#{k}=#{v}" } unless args.empty?
31
+
32
+ result = access_token.get("#{API_BASE}#{API_PATH}#{search}")
33
+ raise ServiceError.new(result.code, result.body) unless ["200", "404"].include? result.code
34
+
35
+ if result.code == "200"
36
+ JSON.parse(result.body, symbolize_names: true)[:icons].map { |icon| Icon.new(icon) }
37
+ else
38
+ []
39
+ end
40
+ end
41
+ end
42
+
43
+ # List recent uploads
44
+ # * limit - limit the amount of results
45
+ # * offset - offset the results
46
+ # * page - page number
47
+ def recent_uploads(limit = nil, offset = nil, page = nil)
48
+ args = {
49
+ "limit" => limit,
50
+ "offset" => offset,
51
+ "page" => page
52
+ }.reject { |_, v| v.nil? }
53
+ if !args.empty?
54
+ search = "?"
55
+ args.each { |k, v| search += "#{k}=#{v}&" }
56
+ else
57
+ search = ""
58
+ end
59
+
60
+ result = access_token.get("#{API_BASE}#{API_PATH}recent_uploads#{search}")
61
+ raise ServiceError.new(result.code, result.body) unless result.code == "200"
62
+
63
+ JSON.parse(result.body, symbolize_names: true)[:recent_uploads].map { |icon| Icon.new(icon) }
64
+ end
65
+ end
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
- @collection = NounProjectApi::CollectionRetriever.new(Faker::Internet.password(16), Faker::Internet.password(16))
7
- @valid_hash = JSON.parse(Fakes::Results::COLLECTION_VALID)
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)
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
- @icon = NounProjectApi::IconRetriever.new(Faker::Internet.password(16), Faker::Internet.password(16))
7
- @valid_hash = JSON.parse(Fakes::Results::ICON_VALID)
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)
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,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  RSpec.describe NounProjectApi::IconsRetriever do
4
6
  before :each do
5
- @icons = NounProjectApi::IconsRetriever.new(Faker::Internet.password(16), Faker::Internet.password(16))
7
+ @icons = NounProjectApi::IconsRetriever.new(Faker::Internet.password(min_length: 16), Faker::Internet.password(min_length: 16))
6
8
  end
7
9
 
8
10
  context "recent uploads" 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,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  RSpec.describe NounProjectApi::Reporter do
4
6
  it "raises an error when initialized without token" do
5
- expect { NounProjectApi::Reporter.new(nil, Faker::Internet.password(16)) }.to raise_error(ArgumentError)
7
+ expect { NounProjectApi::Reporter.new(nil, Faker::Internet.password(min_length: 16)) }.to raise_error(ArgumentError)
6
8
  end
7
9
 
8
10
  it "raises an error when initialized without secret" do
9
- expect { NounProjectApi::Reporter.new(Faker::Internet.password(16), nil) }.to raise_error(ArgumentError)
11
+ expect { NounProjectApi::Reporter.new(Faker::Internet.password(min_length: 16), nil) }.to raise_error(ArgumentError)
10
12
  end
11
13
 
12
14
  it "initializes the values properly" do
13
- token = Faker::Internet.password(16)
14
- secret = Faker::Internet.password(16)
15
+ token = Faker::Internet.password(min_length: 16)
16
+ secret = Faker::Internet.password(min_length: 16)
15
17
  reporter = NounProjectApi::Reporter.new(token, secret)
16
18
 
17
19
  expect(reporter.token).to eq(token)
@@ -20,8 +22,8 @@ RSpec.describe NounProjectApi::Reporter do
20
22
 
21
23
  context "reports ids usage" do
22
24
  before :each do
23
- token = Faker::Internet.password(16)
24
- secret = Faker::Internet.password(16)
25
+ token = Faker::Internet.password(min_length: 16)
26
+ secret = Faker::Internet.password(min_length: 16)
25
27
  @reporter = NounProjectApi::Reporter.new(token, secret)
26
28
  end
27
29
 
@@ -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,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  RSpec.describe NounProjectApi::Retriever do
4
6
  it "raises an error when initialized without token" do
5
- expect { NounProjectApi::Retriever.new(nil, Faker::Internet.password(16)) }.to raise_error(ArgumentError)
7
+ expect { NounProjectApi::Retriever.new(nil, Faker::Internet.password(min_length: 16)) }.to raise_error(ArgumentError)
6
8
  end
7
9
 
8
10
  it "raises an error when initialized without secret" do
9
- expect { NounProjectApi::Retriever.new(Faker::Internet.password(16), nil) }.to raise_error(ArgumentError)
11
+ expect { NounProjectApi::Retriever.new(Faker::Internet.password(min_length: 16), nil) }.to raise_error(ArgumentError)
10
12
  end
11
13
 
12
14
  it "initializes the values properly" do
13
- token = Faker::Internet.password(16)
14
- secret = Faker::Internet.password(16)
15
+ token = Faker::Internet.password(min_length: 16)
16
+ secret = Faker::Internet.password(min_length: 16)
15
17
  retriever = NounProjectApi::Retriever.new(token, secret)
16
18
 
17
19
  expect(retriever.token).to eq(token)
@@ -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,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noun-project-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
- - Nadav Shatz
7
+ - Tailor Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-06 00:00:00.000000000 Z
11
+ date: 2022-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: oauth
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -25,61 +39,61 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0.5'
27
41
  - !ruby/object:Gem::Dependency
28
- name: rake
42
+ name: faker
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '12.3'
47
+ version: '2.13'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '12.3'
54
+ version: '2.13'
41
55
  - !ruby/object:Gem::Dependency
42
- name: rspec
56
+ name: pry
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '3.8'
61
+ version: '0.13'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '3.8'
68
+ version: '0.13'
55
69
  - !ruby/object:Gem::Dependency
56
- name: faker
70
+ name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '1.9'
75
+ version: '13.0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '1.9'
82
+ version: '13.0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: semver
84
+ name: rspec
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '1.0'
89
+ version: '3.9'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '1.0'
96
+ version: '3.9'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rspec_junit_formatter
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -95,46 +109,46 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0.4'
97
111
  - !ruby/object:Gem::Dependency
98
- name: pry
112
+ name: rubocop
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - "~>"
115
+ - - '='
102
116
  - !ruby/object:Gem::Version
103
- version: '0.11'
117
+ version: 0.79.0
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - "~>"
122
+ - - '='
109
123
  - !ruby/object:Gem::Version
110
- version: '0.11'
124
+ version: 0.79.0
111
125
  description: A Gem to expose a wrapping API for The Noun Project API's
112
- email: nadav@tailorbrands.com
126
+ email: sloths@tailorbrands.com
113
127
  executables: []
114
128
  extensions: []
115
129
  extra_rdoc_files: []
116
130
  files:
117
131
  - Rakefile
118
- - lib/noun-project-api.rb
119
- - lib/noun-project-api/base_item.rb
120
- - lib/noun-project-api/collection.rb
121
- - lib/noun-project-api/collection_retriever.rb
122
- - lib/noun-project-api/connection.rb
123
- - lib/noun-project-api/errors.rb
124
- - lib/noun-project-api/icon.rb
125
- - lib/noun-project-api/icon_retriever.rb
126
- - lib/noun-project-api/icons_retriever.rb
127
- - lib/noun-project-api/reporter.rb
128
- - lib/noun-project-api/retriever.rb
129
- - spec/lib/noun-project-api/base_item_spec.rb
130
- - spec/lib/noun-project-api/collection_retriever_spec.rb
131
- - spec/lib/noun-project-api/collection_spec.rb
132
- - spec/lib/noun-project-api/icon_retriever_spec.rb
133
- - spec/lib/noun-project-api/icon_spec.rb
134
- - spec/lib/noun-project-api/icons_retriever_spec.rb
135
- - spec/lib/noun-project-api/reporter_spec.rb
136
- - spec/lib/noun-project-api/retriever_spec.rb
137
- - 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
138
152
  - spec/spec_helper.rb
139
153
  - spec/support/fakes.rb
140
154
  homepage: https://github.com/TailorBrands/noun-project-api
@@ -156,20 +170,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
170
  - !ruby/object:Gem::Version
157
171
  version: '0'
158
172
  requirements: []
159
- rubyforge_project:
160
- rubygems_version: 2.7.6
173
+ rubygems_version: 3.2.32
161
174
  signing_key:
162
175
  specification_version: 4
163
176
  summary: An API wrapper for The Noun Project API's
164
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
165
187
  - spec/spec_helper.rb
166
188
  - spec/support/fakes.rb
167
- - spec/lib/nount_project_api_spec.rb
168
- - spec/lib/noun-project-api/collection_spec.rb
169
- - spec/lib/noun-project-api/icon_spec.rb
170
- - spec/lib/noun-project-api/base_item_spec.rb
171
- - spec/lib/noun-project-api/collection_retriever_spec.rb
172
- - spec/lib/noun-project-api/retriever_spec.rb
173
- - spec/lib/noun-project-api/icon_retriever_spec.rb
174
- - spec/lib/noun-project-api/reporter_spec.rb
175
- - 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,59 +0,0 @@
1
- require "noun-project-api/retriever"
2
-
3
- module NounProjectApi
4
- # Retrieve icons.
5
- class IconsRetriever < Retriever
6
- API_PATH = "/icons/".freeze
7
-
8
- # Finds multiple icons based on the term
9
- # * term - search term
10
- # * limit - limit the amount of results
11
- # * offset - offset the results
12
- # * page - page number
13
- def find(term, limit = nil, offset = nil, page = nil)
14
- raise ArgumentError.new("Missing search term") unless term
15
-
16
- search = OAuth::Helper.escape(term)
17
- search += "?limit_to_public_domain=#{NounProjectApi.configuration.public_domain ? 1 : 0}"
18
-
19
- args = {
20
- "limit" => limit,
21
- "offset" => offset,
22
- "page" => page
23
- }.reject { |_, v| v.nil? }
24
- args.each { |k, v| search += "&#{k}=#{v}" } if args.size > 0
25
-
26
- result = access_token.get("#{API_BASE}#{API_PATH}#{search}")
27
- raise ArgumentError.new("Bad request") unless %w(200 404).include? result.code
28
-
29
- if result.code == "200"
30
- JSON.parse(result.body)["icons"].map { |icon| Icon.new(icon) }
31
- else
32
- []
33
- end
34
- end
35
-
36
- # List recent uploads
37
- # * limit - limit the amount of results
38
- # * offset - offset the results
39
- # * page - page number
40
- def recent_uploads(limit = nil, offset = nil, page = nil)
41
- args = {
42
- "limit" => limit,
43
- "offset" => offset,
44
- "page" => page
45
- }.reject { |_, v| v.nil? }
46
- if args.size > 0
47
- search = "?"
48
- args.each { |k, v| search += "#{k}=#{v}&" }
49
- else
50
- search = ""
51
- end
52
-
53
- result = access_token.get("#{API_BASE}#{API_PATH}recent_uploads#{search}")
54
- raise ArgumentError.new("Bad request") unless result.code == "200"
55
-
56
- JSON.parse(result.body)["recent_uploads"].map { |icon| Icon.new(icon) }
57
- end
58
- end
59
- end
@@ -1,33 +0,0 @@
1
- require "oauth"
2
- require "json"
3
- require "noun-project-api/errors"
4
- require "noun-project-api/connection"
5
- require "noun-project-api/icon_retriever"
6
- require "noun-project-api/reporter"
7
- require "noun-project-api/icons_retriever"
8
- require "noun-project-api/icon"
9
- require "noun-project-api/collection_retriever"
10
- require "noun-project-api/collection"
11
-
12
- # Top level name space for the entire Gem.
13
- module NounProjectApi
14
- API_BASE = "http://api.thenounproject.com".freeze
15
-
16
- def self.configuration
17
- @configuration ||= Configuration.new
18
- end
19
-
20
- def self.configure
21
- self.configuration ||= Configuration.new
22
- yield(configuration) if block_given?
23
- end
24
-
25
- # Main configuration class.
26
- class Configuration
27
- attr_accessor :public_domain
28
-
29
- def initialize
30
- @public_domain = false
31
- end
32
- end
33
- end