credly 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cbfda88cb9f0b74434154eeaf2c30b2b2f57eca2
4
+ data.tar.gz: 23052d6d8f5a1fb29b4d0a847fc66f15efd30284
5
+ SHA512:
6
+ metadata.gz: b1454967c24553f048ab0a83dfcd05a6a99f504a772ab01ed6af778e2bb3760a7d455cbb9b8e6dd7719baacf92fbcd83f6c450e099837b926839d1c544e0c6e6
7
+ data.tar.gz: 56363883bd24100f2a1f3d81f4d9d1e8e35e5481deb24e4c705cbfa59cc8848cf8574d720dc9c415498807f62e768fcca3bf454352a4b67d1c1cfbc07b3e9305
@@ -0,0 +1 @@
1
+ tmp/
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 2.0.0" > .rvmrc
9
+ environment_id="ruby-2.0.0-p247@credly-client"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.21.3 (master)" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
27
+ do
28
+ if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
29
+ then \. "${__hook}" || true
30
+ fi
31
+ done
32
+ unset __hook
33
+ if (( ${rvm_use_flag:=1} >= 2 )) # display only when forced
34
+ then
35
+ if [[ $- == *i* ]] # check for interactive shells
36
+ then printf "%b" "Using: \E[32m$GEM_HOME\E[0m
37
+ " # show the user the ruby and gemset they are using in green
38
+ else printf "%b" "Using: $GEM_HOME
39
+ " # don't use colors in non-interactive shells
40
+ fi
41
+ fi
42
+ else
43
+ # If the environment file has not yet been created, use the RVM CLI to select.
44
+ rvm --create "$environment_id" || {
45
+ echo "Failed to create RVM environment '${environment_id}'."
46
+ return 1
47
+ }
48
+ fi
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # gem 'faraday', :github => 'spagalloco/faraday', :branch => 'log_bodies'
4
+
5
+ gemspec
@@ -0,0 +1,113 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ credly (0.0.1)
5
+ activesupport
6
+ faraday
7
+ multi_json
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (4.0.0)
13
+ i18n (~> 0.6, >= 0.6.4)
14
+ minitest (~> 4.2)
15
+ multi_json (~> 1.3)
16
+ thread_safe (~> 0.1)
17
+ tzinfo (~> 0.3.37)
18
+ atomic (1.1.10)
19
+ awesome_print (1.1.0)
20
+ coderay (1.0.9)
21
+ columnize (0.3.6)
22
+ debugger (1.6.0)
23
+ columnize (>= 0.3.1)
24
+ debugger-linecache (~> 1.2.0)
25
+ debugger-ruby_core_source (~> 1.2.1)
26
+ debugger-linecache (1.2.0)
27
+ debugger-ruby_core_source (1.2.3)
28
+ diff-lcs (1.2.4)
29
+ fabrication (2.7.2)
30
+ faraday (0.8.7)
31
+ multipart-post (~> 1.1)
32
+ ffi (1.9.0)
33
+ formatador (0.2.4)
34
+ fuubar (1.1.1)
35
+ rspec (~> 2.0)
36
+ rspec-instafail (~> 0.2.0)
37
+ ruby-progressbar (~> 1.0)
38
+ guard (1.8.1)
39
+ formatador (>= 0.2.4)
40
+ listen (>= 1.0.0)
41
+ lumberjack (>= 1.0.2)
42
+ pry (>= 0.9.10)
43
+ thor (>= 0.14.6)
44
+ guard-bundler (1.0.0)
45
+ bundler (~> 1.0)
46
+ guard (~> 1.1)
47
+ guard-rspec (3.0.2)
48
+ guard (>= 1.8)
49
+ rspec (~> 2.13)
50
+ i18n (0.6.4)
51
+ json_spec (1.1.1)
52
+ multi_json (~> 1.0)
53
+ rspec (~> 2.0)
54
+ listen (1.2.2)
55
+ rb-fsevent (>= 0.9.3)
56
+ rb-inotify (>= 0.9)
57
+ rb-kqueue (>= 0.2)
58
+ lumberjack (1.0.4)
59
+ method_source (0.8.1)
60
+ minitest (4.7.5)
61
+ multi_json (1.7.7)
62
+ multipart-post (1.2.0)
63
+ pry (0.9.12.2)
64
+ coderay (~> 1.0.5)
65
+ method_source (~> 0.8)
66
+ slop (~> 3.4)
67
+ pry-debugger (0.2.2)
68
+ debugger (~> 1.3)
69
+ pry (~> 0.9.10)
70
+ rake (10.1.0)
71
+ rb-fchange (0.0.6)
72
+ ffi
73
+ rb-fsevent (0.9.3)
74
+ rb-inotify (0.9.0)
75
+ ffi (>= 0.5.0)
76
+ rb-kqueue (0.2.0)
77
+ ffi (>= 0.5.0)
78
+ rspec (2.13.0)
79
+ rspec-core (~> 2.13.0)
80
+ rspec-expectations (~> 2.13.0)
81
+ rspec-mocks (~> 2.13.0)
82
+ rspec-core (2.13.1)
83
+ rspec-expectations (2.13.0)
84
+ diff-lcs (>= 1.1.3, < 2.0)
85
+ rspec-instafail (0.2.4)
86
+ rspec-mocks (2.13.1)
87
+ ruby-progressbar (1.1.1)
88
+ ruby_gntp (0.3.4)
89
+ slop (3.4.5)
90
+ thor (0.18.1)
91
+ thread_safe (0.1.0)
92
+ atomic
93
+ tzinfo (0.3.37)
94
+
95
+ PLATFORMS
96
+ ruby
97
+
98
+ DEPENDENCIES
99
+ awesome_print
100
+ credly!
101
+ fabrication
102
+ faraday
103
+ fuubar
104
+ guard-bundler
105
+ guard-rspec
106
+ json_spec
107
+ pry-debugger
108
+ rake
109
+ rb-fchange
110
+ rb-fsevent
111
+ rb-inotify
112
+ rspec
113
+ ruby_gntp
@@ -0,0 +1,5 @@
1
+ guard 'rspec', :cli => "--color --format Fuubar" do
2
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec" }
3
+ watch(%r{^spec/(.+)\.rb$})
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require File.expand_path('../lib/credly/version', __FILE__)
4
+
5
+ desc "Build"
6
+ task "build" do
7
+ system("gem build credly.gemspec")
8
+ end
9
+
10
+ desc "Build and publish the gem"
11
+ task :publish => :build do
12
+ tags = `git tag`
13
+ system("git tag #{Credly::VERSION}") unless tags =~ /#{Credly::VERSION}/
14
+ system("gem push credly-#{Credly::VERSION}.gem")
15
+ system("git push --tags")
16
+ end
17
+
18
+ task :release => :publish do
19
+ end
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/credly/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Gonzalo Rodríguez-Baltanás Díaz"]
6
+ gem.email = ["gonzalor@haikuls.com"]
7
+ gem.description = %q{ruby client for the Credly API}
8
+ gem.homepage = "https://github.com/haikulearning/credly"
9
+ gem.summary = gem.description
10
+
11
+ gem.name = "credly"
12
+ gem.require_paths = ["lib"]
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.version = Credly::VERSION
15
+
16
+ gem.add_dependency 'faraday'
17
+ gem.add_dependency 'activesupport'
18
+ gem.add_dependency 'multi_json'
19
+
20
+ gem.add_development_dependency 'rake'
21
+ gem.add_development_dependency 'pry-debugger'
22
+ gem.add_development_dependency 'json_spec'
23
+ gem.add_development_dependency 'rspec'
24
+ gem.add_development_dependency 'guard-bundler'
25
+ gem.add_development_dependency 'guard-rspec'
26
+ gem.add_development_dependency 'rb-inotify'
27
+ gem.add_development_dependency 'rb-fsevent'
28
+ gem.add_development_dependency 'rb-fchange'
29
+ gem.add_development_dependency 'ruby_gntp'
30
+ gem.add_development_dependency 'faraday'
31
+ gem.add_development_dependency 'fabrication'
32
+ gem.add_development_dependency 'fuubar'
33
+ gem.add_development_dependency 'awesome_print'
34
+
35
+ end
@@ -0,0 +1,81 @@
1
+ module Credly
2
+ attr_accessor :options
3
+
4
+ def self.base_endpoint=(endpoint)
5
+ options[:base_endpoint] = endpoint
6
+ end
7
+
8
+ def self.base_endpoint
9
+ options[:base_endpoint]
10
+ end
11
+
12
+ def self.debugging=(debugging)
13
+ options[:debugging] = debugging
14
+ end
15
+
16
+ def self.debugging
17
+ options[:debugging]
18
+ end
19
+
20
+ def self.debugging?
21
+ !!options[:debugging]
22
+ end
23
+
24
+ def self.user_agent=(user_agent)
25
+ options[:user_agent] = user_agent
26
+ end
27
+
28
+ def self.user_agent
29
+ options[:user_agent]
30
+ end
31
+
32
+ def self.auth_token=(auth_token)
33
+ options[:auth_token] = auth_token
34
+ end
35
+
36
+ def self.auth_token
37
+ options[:auth_token]
38
+ end
39
+
40
+ def self.version=(version)
41
+ options[:version] = version
42
+ end
43
+
44
+ def self.version
45
+ options[:version]
46
+ end
47
+
48
+ def self.options
49
+ if defined? @@options
50
+ @@options
51
+ else
52
+ @@options = { :base_endpoint => 'https://apistaging2.credly.com',
53
+ :auth_token => nil,
54
+ :version => 'v0.2',
55
+ :debugging => false,
56
+ :user_agent => 'credly_ruby_client' }
57
+ end
58
+ end
59
+
60
+ def self.configuration
61
+ if block_given?
62
+ yield(self)
63
+ else
64
+ options
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ require 'active_support/all'
71
+
72
+ require 'credly/version'
73
+ require 'credly/connection'
74
+ require 'credly/response/follow_redirects'
75
+ require 'credly/requierable'
76
+ require 'credly/api'
77
+ require 'credly/client'
78
+
79
+ require 'credly/api/base'
80
+
81
+ Dir[File.dirname(__FILE__) + "/credly/api/*"].each {|file| require file }
@@ -0,0 +1,33 @@
1
+ require 'forwardable'
2
+
3
+ module Credly
4
+ class Api
5
+ extend Forwardable
6
+
7
+ attr_accessor :client
8
+
9
+ def_delegators :@client, :get, :post, :request, :put, :delete, :patch
10
+
11
+ def initialize(client)
12
+ @client = client
13
+ end
14
+
15
+ private
16
+
17
+ def self.endpoint(name)
18
+ define_method name do
19
+ $endpoint_resource = name.to_s if ENV['testing']
20
+ Api::const_get(name.to_s.camelize).new(:client => @client)
21
+ end
22
+ end
23
+
24
+ def self.endpoints(*names)
25
+ names.each { |name| endpoint(name) }
26
+ end
27
+
28
+ public
29
+
30
+ endpoints :badges, :member_badges, :members
31
+
32
+ end
33
+ end
@@ -0,0 +1,27 @@
1
+ module Credly
2
+ class Api
3
+ class Badges < Base
4
+
5
+ def all(options = Hash.new)
6
+ get("badges", options)
7
+ end
8
+
9
+ def create(options = Hash.new)
10
+ post('badges', options)
11
+ end
12
+
13
+ def find(id, options = Hash.new)
14
+ get("badges/#{id}", options)
15
+ end
16
+
17
+ def update(id, options = Hash.new)
18
+ post("badges/#{id}", options)
19
+ end
20
+
21
+ def categories
22
+ Categories.new(:client => @client)
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,53 @@
1
+ require 'ostruct'
2
+
3
+ module Credly
4
+ class Api
5
+ class Base
6
+ extend Forwardable
7
+ include Requierable
8
+
9
+ attr_accessor :response
10
+
11
+ def initialize(options = Hash.new)
12
+ @client = options[:client]
13
+ end
14
+
15
+ def build_object
16
+ return OpenStruct.new(MultiJson.load(@response))
17
+ end
18
+
19
+ def before_request(*args)
20
+ end
21
+
22
+ def get(*args)
23
+ before_request(*args)
24
+ @response = @client.get(*args)
25
+ build_object
26
+ end
27
+
28
+ def post(*args)
29
+ before_request(*args)
30
+ @response = @client.post(*args)
31
+ build_object
32
+ end
33
+
34
+ def put(*args)
35
+ before_request(*args)
36
+ @response = @client.put(*args)
37
+ build_object
38
+ end
39
+
40
+ def delete(*args)
41
+ before_request(*args)
42
+ @response = @client.delet(*args)
43
+ build_object
44
+ end
45
+
46
+ def patch(*args)
47
+ before_request(*args)
48
+ @response = @client.patch(*args)
49
+ build_object
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,13 @@
1
+ module Credly
2
+ class Api
3
+ class Badges < Base
4
+
5
+ class Categories < Base
6
+ def all(options = Hash.new)
7
+ get("badges/categories", options)
8
+ end
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Credly
2
+ class Api
3
+ class MemberBadges < Base
4
+
5
+ class Evidence < Base
6
+ def all(member_badge, options = Hash.new)
7
+ get("member_badges/#{member_badge}/evidence", options)
8
+ end
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ module Credly
2
+ class Api
3
+ class Members < Base
4
+
5
+ class Badges < Base
6
+ def all(member_id, options = Hash.new)
7
+ get("members/#{member_id}/badges", options)
8
+ end
9
+
10
+ def given(member_id, options = Hash.new)
11
+ get("members/#{member_id}/badges/given", options)
12
+ end
13
+ end
14
+
15
+ def all(options = Hash.new)
16
+ get("members", options)
17
+ end
18
+
19
+ def find(id, options = Hash.new)
20
+ get("members/#{id}", options)
21
+ end
22
+
23
+ def badges
24
+ Badges.new(:client => @client)
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ module Credly
2
+ class Api
3
+ class MemberBadges < Base
4
+
5
+ def create(options = Hash.new)
6
+ post('member_badges', options)
7
+ end
8
+
9
+ def find(id, options = Hash.new)
10
+ get("member_badges/#{id}", options)
11
+ end
12
+
13
+ def evidence
14
+ Evidence.new(:client => @client)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,55 @@
1
+ module Credly
2
+ class Client
3
+ include Credly::Connection
4
+ include Requierable
5
+
6
+ attr_accessor :options
7
+
8
+ def initialize(options = Hash.new)
9
+ @options = OpenStruct.new(Credly.options.merge(options))
10
+ end
11
+
12
+ def api
13
+ Api.new(self)
14
+ end
15
+
16
+ def authenticate(username, password)
17
+ connection = new_connection
18
+ connection.basic_auth(username, password)
19
+ resp = connection.post(versioned_path('authenticate'))
20
+ resp = OpenStruct.new(MultiJson.load(resp.body))
21
+ if resp.status_code == 200
22
+ options.auth_token = resp.data['token']
23
+ else
24
+ resp
25
+ end
26
+ end
27
+
28
+ def get(path, params = Hash.new, headers = Hash.new)
29
+ super(versioned_path(path), {:access_token => options.auth_token}.merge(params), headers)
30
+ end
31
+
32
+ def post(path, params = Hash.new, headers = Hash.new)
33
+ super(versioned_path(path), {:access_token => options.auth_token}.merge(params), headers)
34
+ end
35
+
36
+ def put(path, params = Hash.new, headers = Hash.new)
37
+ super(versioned_path(path), {:access_token => options.auth_token}.merge(params), headers)
38
+ end
39
+
40
+ def delete(path, params = Hash.new, headers = Hash.new)
41
+ super(versioned_path(path), {:access_token => options.auth_token}.merge(params), headers)
42
+ end
43
+
44
+ def base_url
45
+ options.base_endpoint
46
+ end
47
+
48
+ private
49
+
50
+ def versioned_path(path)
51
+ [options.version, path].join('/')
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,61 @@
1
+ require 'faraday'
2
+ require 'multi_json'
3
+
4
+ module Credly
5
+ module Connection
6
+
7
+ def new_connection
8
+ default_options = {
9
+ :headers => {
10
+ :accept => 'application/json',
11
+ :content_type => 'application/x-www-form-urlencoded',
12
+ :user_agent => Credly.user_agent,
13
+ }
14
+ }
15
+ Faraday.new(self.base_url, default_options) do |builder|
16
+ builder.use Credly::Response::FollowRedirects
17
+ builder.request :multipart
18
+ builder.request :url_encoded
19
+ # builder.use Faraday::Request::Multipart
20
+ # builder.use Faraday::Request::UrlEncoded
21
+
22
+ builder.response :logger, ::Logger.new(STDOUT), :bodies => true if Credly.debugging?
23
+ builder.adapter Faraday.default_adapter
24
+ end
25
+ end
26
+
27
+ def connection
28
+ @connection ||= new_connection
29
+ end
30
+
31
+ def get(path, params = Hash.new, headers = Hash.new)
32
+ request(:get, path, params, headers)
33
+ end
34
+
35
+ def post(path, params = Hash.new, headers = Hash.new)
36
+ request(:post, path, params, headers)
37
+ end
38
+
39
+ def put(path, params = Hash.new, headers = Hash.new)
40
+ request(:put, path, params, headers)
41
+ end
42
+
43
+ def delete(path, params = Hash.new, headers = Hash.new)
44
+ request(:delete, path, params, headers)
45
+ end
46
+
47
+ def request(method, path, params, headers)
48
+ response = connection.send(method) do |request|
49
+ case method.to_sym
50
+ when :delete, :get
51
+ request.url(path, params)
52
+ when :post, :put
53
+ request.path = path
54
+ request.body = params unless params.empty?
55
+ end
56
+ request.headers.merge!(headers)
57
+ end
58
+ response.body
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,15 @@
1
+ module Credly
2
+ module Requierable
3
+ def require_present(options, *args)
4
+ args.each do |argument|
5
+ raise ArgumentError.new("Argument #{argument} is required") if options[argument].nil?
6
+ end
7
+ end
8
+
9
+ def require_at_least_one_file(options, *args)
10
+ args.each do |argument|
11
+ raise ArgumentError.new('There should be at least one file') if options[argument].empty?
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,44 @@
1
+ module Credly
2
+ module Response
3
+ class RedirectLimitReached < Faraday::Error::ClientError
4
+ attr_reader :response
5
+
6
+ def initialize(response)
7
+ super "too many redirects; last one to: #{response['location']}"
8
+ @response = response
9
+ end
10
+ end
11
+
12
+ class FollowRedirects < Faraday::Middleware
13
+ REDIRECTS = [301, 302, 303, 307]
14
+ # default value for max redirects followed
15
+ FOLLOW_LIMIT = 3
16
+
17
+ def initialize(app, options = {})
18
+ super(app)
19
+ @options = options
20
+ @follow_limit = options[:limit] || FOLLOW_LIMIT
21
+ end
22
+
23
+ def call(env)
24
+ process_response(@app.call(env), @follow_limit)
25
+ end
26
+
27
+ def process_response(response, follows)
28
+ response.on_complete do |env|
29
+ if redirect? response
30
+ raise RedirectLimitReached, response if follows.zero?
31
+ env[:url] += response['location']
32
+ env[:method] = :get
33
+ response = process_response(@app.call(env), follows - 1)
34
+ end
35
+ end
36
+ response
37
+ end
38
+
39
+ def redirect?(response)
40
+ REDIRECTS.include? response.status
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,22 @@
1
+ module Credly
2
+ module Response
3
+ class ParseJson < Faraday::Response::Middleware
4
+ def on_complete(env)
5
+ if respond_to? :parse
6
+ env[:body] = parse(env[:body]) unless [204,302,304,307].index env[:status]
7
+ end
8
+ end
9
+
10
+ def parse(body)
11
+ case body
12
+ when ''
13
+ nil
14
+ else
15
+ response_hash = ::MultiJson.decode(body)
16
+
17
+ #raise LearnSprout::RequestException, response_hash["message"] if response_hash["message"]
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ module Credly
2
+ VERSION = '0.0.1'
3
+
4
+ end
@@ -0,0 +1,76 @@
1
+ # A Ruby client for the Credly API
2
+
3
+ Credly is an Badging service. This is the the API client for the ruby client. You can find Credly's API at https://apidocs2.credly.com/credly.
4
+
5
+ # Configuration
6
+
7
+ This is how you can configure the default values for Credly:
8
+
9
+ ```ruby
10
+ Credly.configuration do |config|
11
+ # These are the default values
12
+ config.base_endpoint = 'apistaging2.credly.com'
13
+ config.version = 'v0.2'
14
+ config.auth_token = nil
15
+ end
16
+ ```
17
+
18
+ You can also:
19
+
20
+ ```ruby
21
+ Credly.configuration.base_endpoint = 'apistaging2.credly.com/v0.2/'
22
+ Credly.configuration.version = 'v0.2'
23
+ Credly.configuration.auth_token = nil
24
+ ```
25
+
26
+ Those options will be the default ones for any `client.api` you create afterwards. Nonetheless, you can overwrite any of these options; just pass it as an argument when you instantiate the client:
27
+
28
+ ```ruby
29
+ client = client.api.new(auth_token: '26287568342')
30
+
31
+ ```
32
+
33
+ Then you instantiate a client and use it to make calls:
34
+ ```ruby
35
+ client = client.api.new()
36
+
37
+ client.api.badges.all
38
+ => #<OpenStruct
39
+ meta={"status_code"=>200, "status"=>"OK", "message"=>"", "more_info"=>nil},
40
+ data=[
41
+ { "id"=>1003,
42
+ "title"=>"asadas",
43
+ "short_description"=>"asdasda",
44
+ "image_url"=>"https://credlyapp.s3.amazonaws.com/badges/6f7791d21e13ca7409146c2343fdf28d.png",
45
+ "is_giveable"=>false,
46
+ "created_at"=>"Thu, 04 Jul 2013 06:33:43 -0400",
47
+ "creator_id"=>147,
48
+ "resources"=>{"url"=>"https://apistaging2.credly.com/v0.2/badges/1003"}},
49
+
50
+ { "id"=>1002,
51
+ "title"=>"asadas",
52
+ "short_description"=>"asdasda",
53
+ "image_url"=>"https://credlyapp.s3.amazonaws.com/badges/6f7791d21e13ca7409146c2343fdf28d.png",
54
+ "is_giveable"=>false,
55
+ "created_at"=>"Thu, 04 Jul 2013 06:31:46 -0400",
56
+ "creator_id"=>147,
57
+ "resources"=>{"url"=>"https://apistaging2.credly.com/v0.2/badges/1002"}}
58
+ ]
59
+ >
60
+
61
+ ```
62
+
63
+ All API endpoints are accessible from `client.api`. The endpoints methods are named after the remote endpoint. So, for example any action on 'https://apistaging2.credly.com/v0.2/members' will be using `client.api.members`.
64
+
65
+ Nested endpoints, like `/members/:id/badges` are also nested in the client
66
+
67
+ ```ruby
68
+ client.api.members.badges
69
+ ```
70
+
71
+ In those cases, the `id` will be the first parameter on the method, as in:
72
+ ```ruby
73
+ client.api.members.badges.all(1, { other_parameter: 'whatever' })
74
+ ```
75
+
76
+ Check https://github.com/haikulearning/credly-ruby/blob/master/spec/unit/api_spec.rb for examples.
@@ -0,0 +1,23 @@
1
+ require_relative '../lib/credly'
2
+
3
+ ENV['testing'] = 'true'
4
+
5
+ RSpec.configure do |config|
6
+
7
+ Dir[File.dirname(__FILE__) + "/support/*.rb"].each {|file| require file }
8
+
9
+ config.filter_run :focus => true
10
+ config.run_all_when_everything_filtered = true
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+
13
+ config.order = "random"
14
+ end
15
+
16
+ def expect_api_call(type, url, *args)
17
+ if ENV['HIT_SERVER']
18
+ Credly::Client.any_instance.should_receive(type).with(url, *args).and_call_original
19
+ else
20
+ Credly::Client.any_instance.should_receive(type).with(url, *args).and_return({ test: "Set ENV['HIT_SERVER'] if you wish to hit the real server and get a real response. This is just being mocked at the moment"}.to_json)
21
+ end
22
+
23
+ end
@@ -0,0 +1,3 @@
1
+ shared_context 'api' do
2
+ let(:client) { Credly::Client.new(:auth_token => 'blablabla')}
3
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'API' do
4
+ include_context 'api'
5
+
6
+ describe 'Badges' do
7
+ it 'list all badges' do
8
+ expect_api_call(:get, 'badges', {})
9
+ client.api.badges.all
10
+ end
11
+
12
+ it 'create a badge' do
13
+ expect_api_call(:post, 'badges', :title => 'my title')
14
+ client.api.badges.create(:title => 'my title')
15
+ end
16
+
17
+ it "update a badge" do
18
+ expect_api_call(:post, 'badges/1', {})
19
+ client.api.badges.update(1, {})
20
+ end
21
+
22
+ it "find a badge" do
23
+ expect_api_call(:get, 'badges/1', {})
24
+ client.api.badges.find(1, {})
25
+ end
26
+
27
+ describe "Categories" do
28
+ it "list categories" do
29
+ expect_api_call(:get, 'badges/categories', {})
30
+ client.api.badges.categories.all({})
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "Member Badges" do
36
+ it "create member badge" do
37
+ expect_api_call(:post, 'member_badges', {})
38
+ client.api.member_badges.create({})
39
+ end
40
+
41
+ it "find a member badge " do
42
+ expect_api_call(:get, 'member_badges/1', {})
43
+ client.api.member_badges.find(1, {})
44
+ end
45
+
46
+ describe "Evidence" do
47
+ it "list all evidence for a member_badge" do
48
+ expect_api_call(:get, 'member_badges/1/evidence', {})
49
+ client.api.member_badges.evidence.all(1, {})
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "Members" do
55
+ it "list all members" do
56
+ expect_api_call(:get, 'members', {})
57
+ client.api.members.all({})
58
+ end
59
+
60
+ it "find a member" do
61
+ expect_api_call(:get, 'members/1', {})
62
+ client.api.members.find(1, {})
63
+ end
64
+
65
+ describe "Badges" do
66
+ it "list all badges of a member" do
67
+ expect_api_call(:get, 'members/1/badges', {})
68
+ client.api.members.badges.all(1, {})
69
+ end
70
+
71
+ it "list all badges a member has given" do
72
+ expect_api_call(:get, 'members/1/badges/given', {})
73
+ client.api.members.badges.given(1, {})
74
+ end
75
+ end
76
+ end
77
+
78
+ end
metadata ADDED
@@ -0,0 +1,306 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: credly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gonzalo Rodríguez-Baltanás Díaz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: multi_json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-debugger
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json_spec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-bundler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rb-inotify
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rb-fsevent
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rb-fchange
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: ruby_gntp
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: faraday
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - '>='
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: fabrication
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - '>='
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - '>='
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: fuubar
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - '>='
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: awesome_print
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - '>='
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - '>='
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ description: ruby client for the Credly API
252
+ email:
253
+ - gonzalor@haikuls.com
254
+ executables: []
255
+ extensions: []
256
+ extra_rdoc_files: []
257
+ files:
258
+ - .gitignore
259
+ - .rvmrc
260
+ - Gemfile
261
+ - Gemfile.lock
262
+ - Guardfile
263
+ - Rakefile
264
+ - credly.gemspec
265
+ - lib/credly.rb
266
+ - lib/credly/api.rb
267
+ - lib/credly/api/badges.rb
268
+ - lib/credly/api/base.rb
269
+ - lib/credly/api/categories.rb
270
+ - lib/credly/api/evidence.rb
271
+ - lib/credly/api/member.rb
272
+ - lib/credly/api/member_badges.rb
273
+ - lib/credly/client.rb
274
+ - lib/credly/connection.rb
275
+ - lib/credly/requierable.rb
276
+ - lib/credly/response/follow_redirects.rb
277
+ - lib/credly/response/parse_json.rb
278
+ - lib/credly/version.rb
279
+ - readme.markdown
280
+ - spec/spec_helper.rb
281
+ - spec/support/contexts.rb
282
+ - spec/unit/api_spec.rb
283
+ homepage: https://github.com/haikulearning/credly
284
+ licenses: []
285
+ metadata: {}
286
+ post_install_message:
287
+ rdoc_options: []
288
+ require_paths:
289
+ - lib
290
+ required_ruby_version: !ruby/object:Gem::Requirement
291
+ requirements:
292
+ - - '>='
293
+ - !ruby/object:Gem::Version
294
+ version: '0'
295
+ required_rubygems_version: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - '>='
298
+ - !ruby/object:Gem::Version
299
+ version: '0'
300
+ requirements: []
301
+ rubyforge_project:
302
+ rubygems_version: 2.0.3
303
+ signing_key:
304
+ specification_version: 4
305
+ summary: ruby client for the Credly API
306
+ test_files: []