badgeapi 0.3.10 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.rubocop.yml +147 -0
  4. data/README.md +44 -12
  5. data/Rakefile +24 -11
  6. data/badgeapi.gemspec +23 -22
  7. data/lib/badgeapi/badge.rb +24 -27
  8. data/lib/badgeapi/badgeapi_object.rb +160 -147
  9. data/lib/badgeapi/collection.rb +6 -9
  10. data/lib/badgeapi/errors/api_error.rb +3 -4
  11. data/lib/badgeapi/errors/badgeapi_error.rb +15 -15
  12. data/lib/badgeapi/errors/invalid_request_error.rb +3 -4
  13. data/lib/badgeapi/recipient.rb +13 -16
  14. data/lib/badgeapi/version.rb +1 -1
  15. data/lib/badgeapi.rb +13 -15
  16. data/test/badge/badge_test.rb +71 -150
  17. data/test/badgeapi_test.rb +4 -0
  18. data/test/collection/collection_test.rb +43 -77
  19. data/test/fixtures/badge_all.yml +113 -0
  20. data/test/fixtures/{bad_api_key.yml → badge_all_bad_user.yml} +14 -13
  21. data/test/fixtures/{all_badges_bad_user.yml → badge_all_badges_bad_user.yml} +16 -57
  22. data/test/fixtures/badge_all_expanded.yml +184 -0
  23. data/test/fixtures/badge_all_from_collection.yml +52 -0
  24. data/test/fixtures/badge_all_issued.yml +99 -0
  25. data/test/fixtures/{all_badges_limited.yml → badge_all_limited.yml} +10 -8
  26. data/test/fixtures/{create_badge.yml → badge_create.yml} +20 -16
  27. data/test/fixtures/{create_new_badge_failure.yml → badge_create_new.yml} +28 -22
  28. data/test/fixtures/badge_destroy.yml +147 -0
  29. data/test/fixtures/badge_destroy_error.yml +147 -0
  30. data/test/fixtures/badge_error.yml +54 -6
  31. data/test/fixtures/{issue_badge_to_bad_user.yml → badge_issue_to_bad_user.yml} +8 -6
  32. data/test/fixtures/badge_issue_to_user.yml +107 -0
  33. data/test/fixtures/{issue_badge_to_user_with_library_card.yml → badge_issue_to_user_with_library_card.yml} +21 -17
  34. data/test/fixtures/{one_badge.yml → badge_one.yml} +10 -8
  35. data/test/fixtures/{one_badge_expanded.yml → badge_one_expanded.yml} +11 -9
  36. data/test/fixtures/badge_requirements.yml +150 -105
  37. data/test/fixtures/badge_revoke_from_user.yml +107 -0
  38. data/test/fixtures/{update_badge_via_update.yml → badge_update_via_update.yml} +31 -25
  39. data/test/fixtures/{update_badge_via_update_slug_history.yml → badge_update_via_update_slug_history.yml} +41 -33
  40. data/test/fixtures/{all_collection.yml → collection_all.yml} +11 -9
  41. data/test/fixtures/collection_all_expanded.yml +123 -0
  42. data/test/fixtures/{all_collection_limit.yml → collection_all_limit.yml} +10 -8
  43. data/test/fixtures/{create_collection.yml → collection_create.yml} +20 -16
  44. data/test/fixtures/{create_new_collection_failure.yml → collection_create_new_failure.yml} +36 -28
  45. data/test/fixtures/{destroy_collection.yml → collection_destroy.yml} +36 -28
  46. data/test/fixtures/{destroy_collection_error.yml → collection_destroy_error.yml} +36 -28
  47. data/test/fixtures/collection_error.yml +108 -12
  48. data/test/fixtures/{one_collection.yml → collection_one.yml} +10 -8
  49. data/test/fixtures/collection_one_expanded.yml +106 -0
  50. data/test/fixtures/{update_collection.yml → collection_update.yml} +40 -32
  51. data/test/fixtures/{update_collection_via_update.yml → collection_update_via_update.yml} +30 -24
  52. data/test/fixtures/{bad_Recipietn_request.yml → recipient_bad_user_data.yml} +26 -22
  53. data/test/fixtures/recipient_with_badges.yml +20 -108
  54. data/test/fixtures/recipient_with_badges_unicard.yml +151 -8
  55. data/test/recipient/recipient_test.rb +11 -29
  56. metadata +69 -73
  57. data/test/fixtures/all_badges.yml +0 -121
  58. data/test/fixtures/all_badges_expanded.yml +0 -196
  59. data/test/fixtures/all_badges_from_collection.yml +0 -52
  60. data/test/fixtures/all_badges_issued.yml +0 -430
  61. data/test/fixtures/all_collection_expanded.yml +0 -131
  62. data/test/fixtures/bad_Recipient.yml +0 -183
  63. data/test/fixtures/destroy_badge.yml +0 -277
  64. data/test/fixtures/destroy_badge_error.yml +0 -231
  65. data/test/fixtures/issue_already_owned_badge.yml +0 -49
  66. data/test/fixtures/issue_badge_to_user.yml +0 -199
  67. data/test/fixtures/one_collection_expanded.yml +0 -104
  68. data/test/fixtures/revoke_badge_from_user.yml +0 -199
  69. data/test/fixtures/revoke_badge_not_issued.yml +0 -49
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0fb85428425957c7619fe7ee0a63e0173d862e9
4
- data.tar.gz: bc580ac603059f82dfe56d03da531b6dcea3ca15
3
+ metadata.gz: 77938855273965df1555a82b886eeb17f8333655
4
+ data.tar.gz: 824f4b0f3d188571b45ea02da501296f1ba2eb0a
5
5
  SHA512:
6
- metadata.gz: b9b3a48f43ad53375124912ffdd1176d8dfd52c343d9c3821268fcbecb696a24c40d816ef42e4cc2c3fb6bdc0ef98053cae9628c958f30e349252604b356f806
7
- data.tar.gz: 775493e635ccbad1d2ecfa640a3965cabbe240340d4e20506e8d8a5e758641d4211c12539fe1f0b5a3e5ade35f274d833d0be93ceef3b944f495999dae24673f
6
+ metadata.gz: 9dfe48d531b39b9e3cf5413309845de41fcf1152ba41c036e8a9c4768b526753b6efce7e242418422e9ceb1e6cd3843d8f0bd1b98584608528b8e173b08b5c78
7
+ data.tar.gz: 9f5ad569beb69dd850e1302e283843cc93697a7d62dc66f94816176e61c1cd3a6788c97c58019c6217e4f9a82d760b6d4721449136b837e01660d4c0571bd605
data/.gitignore CHANGED
@@ -11,4 +11,5 @@ coverage/*
11
11
  doc/*
12
12
  log/*
13
13
  pkg/*
14
- .idea/*
14
+ .idea/*
15
+ .editorconfig
data/.rubocop.yml ADDED
@@ -0,0 +1,147 @@
1
+ AllCops:
2
+ RunRailsCops: true
3
+ Include:
4
+ - Rakefile
5
+ - config.ru
6
+ Exclude:
7
+ - config/initializers/simple_form_bootstrap.rb
8
+ - config/initializers/simple_form.rb
9
+ - db/schema.rb
10
+ - test/**/*
11
+ - db/**/*
12
+ - bin/**/*
13
+
14
+ # Commonly used screens these days easily fit more than 80 characters.
15
+ Metrics/LineLength:
16
+ Max: 120
17
+
18
+ # Too short methods lead to extraction of single-use methods, which can make
19
+ # the code easier to read (by naming things), but can also clutter the class
20
+ Metrics/MethodLength:
21
+ Max: 20
22
+
23
+ # The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
24
+ Metrics/ClassLength:
25
+ Max: 1500
26
+
27
+ # No space makes the method definition shorter and differentiates
28
+ # from a regular assignment.
29
+ # Style/SpaceAroundEqualsInParameterDefault:
30
+ # EnforcedStyle: no_space
31
+
32
+ # Single quotes being faster is hardly measurable and only affects parse time.
33
+ # Enforcing double quotes reduces the times where you need to change them
34
+ # when introducing an interpolation. Use single quotes only if their semantics
35
+ # are needed.
36
+ Style/StringLiterals:
37
+ Enabled: false
38
+
39
+ # We do not need to support Ruby 1.9, so this is good to use.
40
+ Style/SymbolArray:
41
+ Enabled: true
42
+
43
+ # Most readable form.
44
+ Style/AlignHash:
45
+ EnforcedHashRocketStyle: table
46
+ EnforcedColonStyle: table
47
+
48
+ # Mixing the styles looks just silly.
49
+ Style/HashSyntax:
50
+ EnforcedStyle: ruby19_no_mixed_keys
51
+
52
+ # has_key? and has_value? are far more readable than key? and value?
53
+ Style/DeprecatedHashMethods:
54
+ Enabled: false
55
+
56
+ # String#% is by far the least verbose and only object oriented variant.
57
+ Style/FormatString:
58
+ EnforcedStyle: percent
59
+
60
+ Style/CollectionMethods:
61
+ Enabled: true
62
+ PreferredMethods:
63
+ # inject seems more common in the community.
64
+ reduce: "inject"
65
+
66
+
67
+ # Either allow this style or don't. Marking it as safe with parenthesis
68
+ # is silly. Let's try to live without them for now.
69
+ Style/ParenthesesAroundCondition:
70
+ AllowSafeAssignment: false
71
+ Lint/AssignmentInCondition:
72
+ AllowSafeAssignment: false
73
+
74
+ Style/AndOr:
75
+ Enabled: false
76
+
77
+
78
+ # A specialized exception class will take one or more arguments and construct the message from it.
79
+ # So both variants make sense.
80
+ Style/RaiseArgs:
81
+ Enabled: false
82
+
83
+ # Indenting the chained dots beneath each other is not supported by this cop,
84
+ # see https://github.com/bbatsov/rubocop/issues/1633
85
+ Style/MultilineOperationIndentation:
86
+ Enabled: false
87
+
88
+ # Fail is an alias of raise. Avoid aliases, it's more cognitive load for no gain.
89
+ # The argument that fail should be used to abort the program is wrong too,
90
+ # there's Kernel#abort for that.
91
+ Style/SignalException:
92
+ EnforcedStyle: only_raise
93
+
94
+ # Suppressing exceptions can be perfectly fine, and be it to avoid to
95
+ # explicitly type nil into the rescue since that's what you want to return,
96
+ # or suppressing LoadError for optional dependencies
97
+ Lint/HandleExceptions:
98
+ Enabled: false
99
+
100
+ # No trailing space differentiates better from the block:
101
+ # foo} means hash, foo } means block.
102
+ # Style/SpaceInsideHashLiteralBraces:
103
+ # EnforcedStyle: no_space
104
+
105
+ # { ... } for multi-line blocks is okay, follow Weirichs rule instead:
106
+ # https://web.archive.org/web/20140221124509/http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc
107
+ Style/BlockDelimiters:
108
+ Enabled: false
109
+
110
+ # do / end blocks should be used for side effects,
111
+ # methods that run a block for side effects and have
112
+ # a useful return value are rare, assign the return
113
+ # value to a local variable for those cases.
114
+ Style/MethodCalledOnDoEndBlock:
115
+ Enabled: true
116
+
117
+ # Enforcing the names of variables? To single letter ones? Just no.
118
+ Style/SingleLineBlockParams:
119
+ Enabled: false
120
+
121
+ # Shadowing outer local variables with block parameters is often useful
122
+ # to not reinvent a new name for the same thing, it highlights the relation
123
+ # between the outer variable and the parameter. The cases where it's actually
124
+ # confusing are rare, and usually bad for other reasons already, for example
125
+ # because the method is too long.
126
+ Lint/ShadowingOuterLocalVariable:
127
+ Enabled: false
128
+
129
+ # Check with yard instead.
130
+ Style/Documentation:
131
+ Enabled: false
132
+
133
+ # This is just silly. Calling the argument `other` in all cases makes no sense.
134
+ Style/OpMethod:
135
+ Enabled: false
136
+
137
+ # There are valid cases, for example debugging Cucumber steps,
138
+ # also they'll fail CI anyway
139
+ Lint/Debugger:
140
+ Enabled: false
141
+
142
+ # Style preference
143
+ Style/MethodDefParentheses:
144
+ Enabled: false
145
+
146
+ Style/FileName:
147
+ Enabled: false
data/README.md CHANGED
@@ -1,13 +1,21 @@
1
- # .
1
+ # Lancaster University Badge API Gem
2
2
 
3
- TODO: Write a gem description
3
+ The <strong>badgeapi</strong> gem provides Ruby bindings for the [Lancaster University Badge API](http://innovationhub.lancaster.ac.uk/projects/gamification) platform. It allows for quicker and easier access, insertion and consumption of data from the API.
4
+
5
+ ## Documentation
6
+
7
+ You can find API documentation and examples of how to use this gem at the [Badge API Docs](http://badgeapi.lancaster.ac.uk).
8
+
9
+ ## Requirements
10
+
11
+ Your application will need to make request via SSL/HTTPS. If you are developing locally the [rechampoulier/tunnelss](https://github.com/rchampourlier/tunnelss) can be used but you will need to follow the Certificate Authority Fix below.
4
12
 
5
13
  ## Installation
6
14
 
7
15
  Add this line to your application's Gemfile:
8
16
 
9
17
  ```ruby
10
- gem '.'
18
+ gem badgeapi
11
19
  ```
12
20
 
13
21
  And then execute:
@@ -16,16 +24,40 @@ And then execute:
16
24
 
17
25
  Or install it yourself as:
18
26
 
19
- $ gem install .
27
+ $ gem install badgeapi
28
+
29
+ You will need to provide your api key to the gem:
30
+
31
+ ```ruby
32
+ Badgeapi.api_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
33
+ ```
34
+
35
+ ### Certificate Authority Fix
36
+
37
+ The gem relies on Faraday to make the http requests to the API. If you get get any Farday SSL errors, this is because Farday cannot find your CA Certificate. More info at [Faraday: Setting up SSL certificates](https://github.com/lostisland/faraday/wiki/Setting-up-SSL-certificates).
38
+
39
+ Once you know the location of your CA certificates path your can provide this to the gem via:
40
+
41
+ ```ruby
42
+ Badgeapi.ssl_ca_cert='/usr/lib/ssl/certs'
43
+ ```
44
+
45
+ If using [rechampoulier/tunnelss](https://github.com/rchampourlier/tunnelss) for local development.
46
+
47
+ ```ruby
48
+ Badgeapi.ssl_ca_cert='/Users/your_user/.tunnelss/ca/cert.pem'
49
+ ```
50
+
51
+ ## Development
52
+
53
+ Use the gems console:
54
+
55
+ $ rake console
20
56
 
21
- ## Usage
57
+ Run all tests:
22
58
 
23
- TODO: Write usage instructions here
59
+ $ bundle exec rake
24
60
 
25
- ## Contributing
61
+ Run a single test suite:
26
62
 
27
- 1. Fork it ( https://github.com/[my-github-username]/./fork )
28
- 2. Create your feature branch (`git checkout -b my-new-feature`)
29
- 3. Commit your changes (`git commit -am 'Add some feature'`)
30
- 4. Push to the branch (`git push origin my-new-feature`)
31
- 5. Create a new Pull Request
63
+ $ruby test/badge/badge_test.rb
data/Rakefile CHANGED
@@ -1,15 +1,28 @@
1
+ # Console
1
2
  require "bundler/gem_tasks"
2
3
 
3
4
  desc "Open an pry/irb session preloaded with badgeapi"
4
5
  task :console do
5
- irb = "pry"
6
- # Check if pry installed
7
- begin
8
- gem "pry"
9
- rescue Gem::LoadError
10
- irb = "irb"
11
- end
12
- puts "Loading badgeapi gem with #{irb}"
13
-
14
- exec "#{irb} -I lib -r badgeapi.rb"
15
- end
6
+ irb = "pry"
7
+ # Check if pry installed
8
+ begin
9
+ gem "pry"
10
+ rescue Gem::LoadError
11
+ irb = "irb"
12
+ end
13
+ puts "Loading badgeapi gem with #{irb}"
14
+
15
+ exec "#{irb} -I lib -r badgeapi.rb"
16
+ end
17
+
18
+ # Tests
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new do |t|
22
+ t.libs << "test"
23
+ t.test_files = FileList['test/*_test.rb'] + FileList['test/*/*_test.rb']
24
+ t.verbose = true
25
+ end
26
+
27
+ desc "Run tests"
28
+ task default: :test
data/badgeapi.gemspec CHANGED
@@ -4,30 +4,31 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'badgeapi/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "badgeapi"
8
- spec.version = Badgeapi::VERSION
9
- spec.authors = ["Tom Skarbek Wazynski"]
10
- spec.email = ["wazynski@gmail.com"]
11
- spec.summary = %q{A basic API wrapper for Lancaster University's Badge API.}
12
- spec.description = %q{Allows you to connect to Lancaster University's Badge API to manipulate badges, issue badges and display badges.}
13
- spec.homepage = "http://innovationhub.lancaster.ac.uk"
14
- spec.license = "MIT"
7
+ spec.name = "badgeapi"
8
+ spec.version = Badgeapi::VERSION
9
+ spec.authors = ["Tom Skarbek Wazynski"]
10
+ spec.email = ["wazynski@gmail.com"]
11
+ spec.summary = "A basic API wrapper for Lancaster University's Badge API"
12
+ spec.description = "Allows you to connect to Lancaster University's Badge API
13
+ to manipulate badges, issue badges and display badges."
14
+ spec.homepage = "http://innovationhub.lancaster.ac.uk"
15
+ spec.license = "MIT"
15
16
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
20
21
 
21
- spec.add_development_dependency "minitest", "~> 5.5"
22
- spec.add_development_dependency "minitest-focus", "~> 1.1"
23
- spec.add_development_dependency "vcr", "~> 2.9"
24
- spec.add_development_dependency "webmock", "~> 1.20"
22
+ spec.add_development_dependency "minitest", "~> 5.5"
23
+ spec.add_development_dependency "minitest-focus", "~> 1.1"
24
+ spec.add_development_dependency "vcr", "~> 2.9"
25
+ spec.add_development_dependency "webmock", "~> 1.20"
25
26
 
26
- # So it works with rails 4 and 3
27
- spec.add_dependency "activesupport", "> 3.2"
28
- spec.add_dependency "faraday", "~> 0.9"
29
- spec.add_dependency "json", "~> 1.8"
27
+ # So it works with rails 4 and 3
28
+ spec.add_dependency "activesupport", "> 3.2"
29
+ spec.add_dependency "faraday", "~> 0.9"
30
+ spec.add_dependency "json", "~> 1.8"
30
31
 
31
- spec.add_development_dependency "bundler", "~> 1.7"
32
- spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "bundler", "~> 1.7"
33
+ spec.add_development_dependency "rake", "~> 10.0"
33
34
  end
@@ -1,29 +1,26 @@
1
- #lib/badgeapi/badge.rb
1
+ # lib/badgeapi/badge.rb
2
2
  module Badgeapi
3
- class Badge < BadgeapiObject
4
-
5
- attr_reader :id, :created_at, :updated_at, :collection, :points, :required_badges, :image, :object, :recipients
6
- attr_accessor :name, :description, :requirements, :requirements, :hint, :recipient_id, :collection_id, :issuer_id, :issued_at, :level, :auto_issue, :status
7
-
8
-
9
- class << self
10
-
11
- def issue id, params = {}
12
- request "post", "#{Badgeapi.api_url}/#{collection_path}/#{id}/issue", params
13
- end
14
-
15
- def revoke id, params = {}
16
- request "post", "#{Badgeapi.api_url}/#{collection_path}/#{id}/revoke", params
17
- end
18
-
19
- def add_badge_requirement id, required_id
20
- request "post", "#{Badgeapi.api_url}/#{collection_path}/#{id}/requires", {required_badge: {id: required_id}}
21
- end
22
-
23
- def remove_badge_requirement id, required_id
24
- request "delete", "#{Badgeapi.api_url}/#{collection_path}/#{id}/requires", {required_badge: {id: required_id}}
25
- end
26
-
27
- end
28
- end
3
+ class Badge < BadgeapiObject
4
+ attr_reader :id, :created_at, :updated_at, :collection, :points, :required_badges, :image, :object, :recipients
5
+ attr_accessor :name, :description, :requirements, :requirements, :hint, :recipient_id, :collection_id, :issuer_id,
6
+ :issued_at, :level, :auto_issue, :status
7
+
8
+ class << self
9
+ def issue id, params = {}
10
+ request "post", "#{Badgeapi.api_url}/#{collection_path}/#{id}/issue", params
11
+ end
12
+
13
+ def revoke id, params = {}
14
+ request "post", "#{Badgeapi.api_url}/#{collection_path}/#{id}/revoke", params
15
+ end
16
+
17
+ def add_badge_requirement id, required_id
18
+ request "post", "#{Badgeapi.api_url}/#{collection_path}/#{id}/requires", required_badge: { id: required_id }
19
+ end
20
+
21
+ def remove_badge_requirement id, required_id
22
+ request "delete", "#{Badgeapi.api_url}/#{collection_path}/#{id}/requires", required_badge: { id: required_id }
23
+ end
24
+ end
25
+ end
29
26
  end