noun-project-api 0.2.2 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +9 -7
  3. data/lib/noun_project_api.rb +38 -0
  4. data/lib/noun_project_api/base_item.rb +30 -0
  5. data/lib/noun_project_api/collection.rb +36 -0
  6. data/lib/noun_project_api/collection_retriever.rb +14 -0
  7. data/lib/{noun-project-api → noun_project_api}/connection.rb +3 -1
  8. data/lib/noun_project_api/errors.rb +14 -0
  9. data/lib/noun_project_api/icon.rb +41 -0
  10. data/lib/noun_project_api/icon_retriever.rb +14 -0
  11. data/lib/noun_project_api/icons_retriever.rb +66 -0
  12. data/lib/noun_project_api/reporter.rb +22 -0
  13. data/lib/noun_project_api/retriever.rb +18 -0
  14. data/spec/lib/noun_project_api/base_item_spec.rb +13 -0
  15. data/spec/lib/noun_project_api/collection_retriever_spec.rb +87 -0
  16. data/spec/lib/noun_project_api/collection_spec.rb +66 -0
  17. data/spec/lib/{noun-project-api → noun_project_api}/icon_retriever_spec.rb +20 -18
  18. data/spec/lib/{noun-project-api → noun_project_api}/icon_spec.rb +21 -19
  19. data/spec/lib/{noun-project-api → noun_project_api}/icons_retriever_spec.rb +27 -25
  20. data/spec/lib/{noun-project-api → noun_project_api}/reporter_spec.rb +24 -24
  21. data/spec/lib/noun_project_api/retriever_spec.rb +22 -0
  22. data/spec/lib/{nount_project_api_spec.rb → noun_project_api_spec.rb} +5 -3
  23. data/spec/spec_helper.rb +3 -4
  24. data/spec/support/fakes.rb +93 -10
  25. metadata +90 -45
  26. data/lib/noun-project-api.rb +0 -30
  27. data/lib/noun-project-api/icon.rb +0 -52
  28. data/lib/noun-project-api/icon_retriever.rb +0 -20
  29. data/lib/noun-project-api/icons_retriever.rb +0 -51
  30. data/lib/noun-project-api/reporter.rb +0 -20
  31. data/lib/noun-project-api/retriever.rb +0 -6
  32. data/spec/lib/noun-project-api/retriever_spec.rb +0 -20
@@ -1,20 +0,0 @@
1
- require 'noun-project-api/retriever'
2
-
3
- module NounProjectApi
4
- # Retrieve an icon.
5
- class IconRetriever < Retriever
6
- API_PATH = '/icon/'
7
-
8
- # Find an icon based on it's id.
9
- def find(id)
10
- fail(ArgumentError, 'Missing id/slug') unless id
11
-
12
- result = access_token.get("#{API_BASE}#{API_PATH}#{id}")
13
- fail(ArgumentError, 'Bad request') unless result.code == '200'
14
-
15
- Icon.new(result.body)
16
- end
17
-
18
- alias_method :find_by_slug, :find
19
- end
20
- end
@@ -1,51 +0,0 @@
1
- require 'noun-project-api/retriever'
2
-
3
- module NounProjectApi
4
- # Retrieve icons.
5
- class IconsRetriever < Retriever
6
- API_PATH = '/icons/'
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
- fail(ArgumentError, '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 = { 'limit' => limit, 'offset' => offset, 'page' => page }.reject { |_, v| v.nil? }
20
- args.each { |k, v| search += "&#{k}=#{v}" } if args.size > 0
21
-
22
- result = access_token.get("#{API_BASE}#{API_PATH}#{search}")
23
- fail(ArgumentError, 'Bad request') unless %w(200 404).include? result.code
24
-
25
- if result.code == '200'
26
- JSON.parse(result.body)['icons'].map { |icon| Icon.new(icon) }
27
- else
28
- []
29
- end
30
- end
31
-
32
- # List recent uploads
33
- # * limit - limit the amount of results
34
- # * offset - offset the results
35
- # * page - page number
36
- def recent_uploads(limit = nil, offset = nil, page = nil)
37
- args = { 'limit' => limit, 'offset' => offset, 'page' => page }.reject { |k, v| v.nil? }
38
- if args.size > 0
39
- search = '?'
40
- args.each { |k, v| search += "#{k}=#{v}&" }
41
- else
42
- search = ''
43
- end
44
-
45
- result = access_token.get("#{API_BASE}#{API_PATH}recent_uploads#{search}")
46
- fail(ArgumentError, 'Bad request') unless result.code == '200'
47
-
48
- JSON.parse(result.body)['recent_uploads'].map { |icon| Icon.new(icon) }
49
- end
50
- end
51
- end
@@ -1,20 +0,0 @@
1
- module NounProjectApi
2
- # Main class to hold reporting actions back to the Noun Project.
3
- class Reporter
4
- include Connection
5
-
6
- API_PATH = '/notify/publish'
7
-
8
- def report_used(ids)
9
- ids = [ids] if ids.is_a?(String) || ids.is_a?(Fixnum)
10
- fail(ArgumentError, 'Missing ids') if ids.nil? || ids.empty?
11
-
12
- result = access_token.post(
13
- "#{API_BASE}#{API_PATH}",
14
- { icons: ids.join(',') }.to_json,
15
- { 'Accept' => 'application/json', 'Content-Type' => 'application/json' }
16
- )
17
- result.code == '200'
18
- end
19
- end
20
- end
@@ -1,6 +0,0 @@
1
- module NounProjectApi
2
- # A base class for different retriever classes.
3
- class Retriever
4
- include Connection
5
- end
6
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe NounProjectApi::Retriever do
4
- it 'raises an error when initialized without token' do
5
- expect { NounProjectApi::Retriever.new(nil, Faker::Internet.password(16)) }.to raise_error(ArgumentError)
6
- end
7
-
8
- it 'raises an error when initialized without secret' do
9
- expect { NounProjectApi::Retriever.new(Faker::Internet.password(16), nil) }.to raise_error(ArgumentError)
10
- end
11
-
12
- it 'initializes the values properly' do
13
- token = Faker::Internet.password(16)
14
- secret = Faker::Internet.password(16)
15
- retriever = NounProjectApi::Retriever.new(token, secret)
16
-
17
- expect(retriever.token).to eq(token)
18
- expect(retriever.secret).to eq(secret)
19
- end
20
- end