credly 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/credly/api/badge_builder.rb +20 -0
- data/lib/credly/api/base.rb +9 -0
- data/lib/credly/client.rb +7 -5
- data/lib/credly/connection.rb +10 -2
- data/lib/credly/version.rb +1 -1
- data/spec/spec_helper.rb +3 -2
- data/spec/unit/api_spec.rb +7 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6615a3f910beb529ce7b0f9841d6abd4ff4dbba1
|
4
|
+
data.tar.gz: 1d0b6704a295443da2bb974015c582f3aea07008
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a125903ef925d81004ebbb8d1c479761aa29d28436097b518019906e5e9d513bfff9d833e60b3807a1e6ae83724793c1ecc0249e66c781f4a2b41a43ad0d5859
|
7
|
+
data.tar.gz: 5f4447e1e247a46d27eebe80364af4f0a4ba98eeb6ab36c036c4b18d5fcdab2240067ceceba5ea32a49a8cac88a07a77c19c93ebb1767df636ae20e9b3d7b033
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Credly
|
2
|
+
class Api
|
3
|
+
class BadgeBuilder < Base
|
4
|
+
def initialize(options = {})
|
5
|
+
super
|
6
|
+
@client = @client.dup
|
7
|
+
@client.connection = @client.new_connection(:base_url => 'https://staging.credly.com')
|
8
|
+
end
|
9
|
+
|
10
|
+
def token
|
11
|
+
post("badge-builder/code", { 'access_token' => @client.access_token })
|
12
|
+
end
|
13
|
+
|
14
|
+
def versioned_path(path)
|
15
|
+
path
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/credly/api/base.rb
CHANGED
@@ -23,35 +23,44 @@ module Credly
|
|
23
23
|
def before_request(*args)
|
24
24
|
end
|
25
25
|
|
26
|
+
def versioned_path(path)
|
27
|
+
[@client.options[:version], path].join('/')
|
28
|
+
end
|
29
|
+
|
26
30
|
def build_object
|
27
31
|
MultiJson.load(@response)
|
28
32
|
end
|
29
33
|
|
30
34
|
def get(*args)
|
35
|
+
args[0] = versioned_path(args[0])
|
31
36
|
before_request(*args)
|
32
37
|
@response = @client.get(*args)
|
33
38
|
after_request(*args)
|
34
39
|
end
|
35
40
|
|
36
41
|
def post(*args)
|
42
|
+
args[0] = versioned_path(args[0])
|
37
43
|
before_request(*args)
|
38
44
|
@response = @client.post(*args)
|
39
45
|
after_request(*args)
|
40
46
|
end
|
41
47
|
|
42
48
|
def put(*args)
|
49
|
+
args[0] = versioned_path(args[0])
|
43
50
|
before_request(*args)
|
44
51
|
@response = @client.put(*args)
|
45
52
|
after_request(*args)
|
46
53
|
end
|
47
54
|
|
48
55
|
def delete(*args)
|
56
|
+
args[0] = versioned_path(args[0])
|
49
57
|
before_request(*args)
|
50
58
|
@response = @client.delet(*args)
|
51
59
|
after_request(*args)
|
52
60
|
end
|
53
61
|
|
54
62
|
def patch(*args)
|
63
|
+
args[0] = versioned_path(args[0])
|
55
64
|
before_request(*args)
|
56
65
|
@response = @client.patch(*args)
|
57
66
|
after_request(*args)
|
data/lib/credly/client.rb
CHANGED
@@ -31,19 +31,19 @@ module Credly
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def get(path, params = {}, headers = {})
|
34
|
-
super(
|
34
|
+
super(path, {:access_token => access_token}.merge(params), headers)
|
35
35
|
end
|
36
36
|
|
37
37
|
def post(path, params = {}, headers = {})
|
38
|
-
super(
|
38
|
+
super(path, {:access_token => access_token}.merge(params), headers)
|
39
39
|
end
|
40
40
|
|
41
41
|
def put(path, params = {}, headers = {})
|
42
|
-
super(
|
42
|
+
super(path, {:access_token => access_token}.merge(params), headers)
|
43
43
|
end
|
44
44
|
|
45
45
|
def delete(path, params = {}, headers = {})
|
46
|
-
super(
|
46
|
+
super(path, {:access_token => access_token}.merge(params), headers)
|
47
47
|
end
|
48
48
|
|
49
49
|
def base_url
|
@@ -66,7 +66,9 @@ module Credly
|
|
66
66
|
Api::Me.new(:client => self, :id => id)
|
67
67
|
end
|
68
68
|
|
69
|
-
|
69
|
+
def badge_builder(id = nil)
|
70
|
+
Api::BadgeBuilder.new(:client => self, :id => id)
|
71
|
+
end
|
70
72
|
|
71
73
|
def versioned_path(path)
|
72
74
|
[options[:version], path].join('/')
|
data/lib/credly/connection.rb
CHANGED
@@ -4,7 +4,7 @@ require 'multi_json'
|
|
4
4
|
module Credly
|
5
5
|
module Connection
|
6
6
|
|
7
|
-
def new_connection
|
7
|
+
def new_connection(options = {})
|
8
8
|
default_options = {
|
9
9
|
:headers => {
|
10
10
|
:accept => 'application/json',
|
@@ -13,14 +13,18 @@ module Credly
|
|
13
13
|
}
|
14
14
|
}
|
15
15
|
|
16
|
-
Faraday.new(self.base_url, default_options) do |builder|
|
16
|
+
Faraday.new(options[:base_url] || self.base_url, default_options) do |builder|
|
17
17
|
builder.use Credly::Response::FollowRedirects
|
18
18
|
builder.request :multipart
|
19
19
|
builder.request :url_encoded
|
20
|
+
|
20
21
|
# builder.use Faraday::Request::Multipart
|
21
22
|
# builder.use Faraday::Request::UrlEncoded
|
22
23
|
|
23
24
|
builder.response :logger, ::Logger.new(STDOUT) if self.options[:debugging]
|
25
|
+
|
26
|
+
# builder.response :logger, ::Logger.new(STDOUT), :bodies => { :request => true, :response => false }
|
27
|
+
|
24
28
|
builder.adapter Faraday.default_adapter
|
25
29
|
end
|
26
30
|
end
|
@@ -29,6 +33,10 @@ module Credly
|
|
29
33
|
@connection ||= new_connection
|
30
34
|
end
|
31
35
|
|
36
|
+
def connection=(con)
|
37
|
+
@connection = con
|
38
|
+
end
|
39
|
+
|
32
40
|
def get(path, params = {}, headers = {})
|
33
41
|
request(:get, path, params, headers)
|
34
42
|
end
|
data/lib/credly/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative '../lib/credly'
|
2
|
+
require 'awesome_print'
|
2
3
|
|
3
4
|
ENV['testing'] = 'true'
|
4
5
|
|
@@ -15,9 +16,9 @@ end
|
|
15
16
|
|
16
17
|
def expect_api_call(type, url, *args)
|
17
18
|
if ENV['HIT_SERVER']
|
18
|
-
Credly::Client.any_instance.should_receive(type).with(url, *args).and_call_original
|
19
|
+
Credly::Client.any_instance.should_receive(type).with(Credly.version + '/' + url, *args).and_call_original
|
19
20
|
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
|
+
Credly::Client.any_instance.should_receive(type).with(Credly.version + '/' + 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
22
|
end
|
22
23
|
|
23
24
|
end
|
data/spec/unit/api_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: credly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gonzalo Rodríguez-Baltanás Díaz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -263,6 +263,7 @@ files:
|
|
263
263
|
- Rakefile
|
264
264
|
- credly.gemspec
|
265
265
|
- lib/credly.rb
|
266
|
+
- lib/credly/api/badge_builder.rb
|
266
267
|
- lib/credly/api/badges.rb
|
267
268
|
- lib/credly/api/base.rb
|
268
269
|
- lib/credly/api/categories.rb
|