yam 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/yam.rb +4 -14
- data/lib/yam/api.rb +5 -3
- data/lib/yam/client.rb +1 -1
- data/lib/yam/configuration.rb +3 -18
- data/lib/yam/connection.rb +2 -7
- data/lib/yam/request.rb +0 -1
- data/lib/yam/version.rb +1 -1
- data/spec/spec_helper.rb +4 -17
- data/spec/yam/client_spec.rb +15 -14
- data/spec/yam_spec.rb +31 -42
- metadata +2 -2
data/lib/yam.rb
CHANGED
@@ -15,9 +15,9 @@
|
|
15
15
|
# See the Apache Version 2.0 License for specific language governing
|
16
16
|
# permissions and limitations under the License.
|
17
17
|
|
18
|
-
require 'yam/version'
|
19
|
-
require 'yam/configuration'
|
20
18
|
require 'yam/client'
|
19
|
+
require 'yam/configuration'
|
20
|
+
require 'yam/version'
|
21
21
|
|
22
22
|
module Yam
|
23
23
|
extend Configuration
|
@@ -27,18 +27,8 @@ module Yam
|
|
27
27
|
attr_accessor :api_client
|
28
28
|
|
29
29
|
# Alias for Yam::Client.new
|
30
|
-
def new(
|
31
|
-
@api_client = Yam::Client.new(
|
32
|
-
end
|
33
|
-
|
34
|
-
# Delegate to Yam::Client
|
35
|
-
def method_missing(method, *args, &block)
|
36
|
-
return super unless new.respond_to?(method)
|
37
|
-
new.send(method, *args, &block)
|
38
|
-
end
|
39
|
-
|
40
|
-
def respond_to?(method, include_private = false)
|
41
|
-
new.respond_to?(method, include_private) || super(method, include_private)
|
30
|
+
def new(oauth_token, endpoint)
|
31
|
+
@api_client = Yam::Client.new(oauth_token, endpoint)
|
42
32
|
end
|
43
33
|
end
|
44
34
|
end
|
data/lib/yam/api.rb
CHANGED
@@ -14,7 +14,6 @@
|
|
14
14
|
#
|
15
15
|
# See the Apache Version 2.0 License for specific language governing
|
16
16
|
# permissions and limitations under the License.
|
17
|
-
#
|
18
17
|
|
19
18
|
# API setup and configuration
|
20
19
|
require 'yam/request'
|
@@ -36,12 +35,15 @@ module Yam
|
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
|
-
def initialize(
|
40
|
-
|
38
|
+
def initialize(oauth_token, endpoint)
|
39
|
+
@oauth_token = oauth_token
|
40
|
+
@endpoint = endpoint
|
41
|
+
setup({})
|
41
42
|
end
|
42
43
|
|
43
44
|
def setup(options={})
|
44
45
|
options = Yam.options.merge(options)
|
46
|
+
|
45
47
|
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
46
48
|
send("#{key}=", options[key])
|
47
49
|
end
|
data/lib/yam/client.rb
CHANGED
data/lib/yam/configuration.rb
CHANGED
@@ -17,27 +17,13 @@
|
|
17
17
|
|
18
18
|
module Yam
|
19
19
|
module Configuration
|
20
|
-
VALID_OPTIONS_KEYS = [
|
21
|
-
:adapter,
|
22
|
-
:endpoint,
|
23
|
-
:oauth_token,
|
24
|
-
:user_agent,
|
25
|
-
].freeze
|
26
|
-
|
27
20
|
DEFAULT_ADAPTER = :net_http
|
28
|
-
|
29
|
-
DEFAULT_ENDPOINT = 'https://www.yammer.com/api/v1'.freeze
|
30
|
-
|
31
|
-
DEFAULT_OAUTH_TOKEN = nil
|
32
|
-
|
21
|
+
DEFAULT_API_ENDPOINT = 'https://www.yammer.com/api/v1/'
|
33
22
|
DEFAULT_USER_AGENT = "Yam Ruby Gem #{Yam::VERSION}".freeze
|
23
|
+
VALID_OPTIONS_KEYS = [:adapter, :endpoint, :user_agent].freeze
|
34
24
|
|
35
25
|
attr_accessor *VALID_OPTIONS_KEYS
|
36
26
|
|
37
|
-
def configure
|
38
|
-
yield self
|
39
|
-
end
|
40
|
-
|
41
27
|
def self.extended(base)
|
42
28
|
base.set_defaults
|
43
29
|
end
|
@@ -50,8 +36,7 @@ module Yam
|
|
50
36
|
|
51
37
|
def set_defaults
|
52
38
|
self.adapter = DEFAULT_ADAPTER
|
53
|
-
self.endpoint =
|
54
|
-
self.oauth_token = DEFAULT_OAUTH_TOKEN
|
39
|
+
self.endpoint = DEFAULT_API_ENDPOINT
|
55
40
|
self.user_agent = DEFAULT_USER_AGENT
|
56
41
|
self
|
57
42
|
end
|
data/lib/yam/connection.rb
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
#
|
15
15
|
# See the Apache Version 2.0 License for specific language governing
|
16
16
|
# permissions and limitations under the License.
|
17
|
-
|
17
|
+
|
18
18
|
require 'faraday'
|
19
19
|
require 'yam/constants'
|
20
20
|
require 'faraday_middleware/response/mashify'
|
@@ -39,7 +39,6 @@ module Yam
|
|
39
39
|
end
|
40
40
|
|
41
41
|
# Returns a Faraday::Connection object
|
42
|
-
#
|
43
42
|
def connection(options = {})
|
44
43
|
conn_options = default_options(options)
|
45
44
|
clear_cache unless options.empty?
|
@@ -49,11 +48,7 @@ module Yam
|
|
49
48
|
conn.use Faraday::Response::Mashify
|
50
49
|
conn.use FaradayMiddleware::ParseJson
|
51
50
|
conn.response :raise_error
|
52
|
-
|
53
|
-
if oauth_token?
|
54
|
-
conn.use FaradayMiddleware::OAuth2, oauth_token
|
55
|
-
end
|
56
|
-
|
51
|
+
conn.use FaradayMiddleware::OAuth2, oauth_token
|
57
52
|
conn.request :url_encoded
|
58
53
|
conn.adapter adapter
|
59
54
|
end
|
data/lib/yam/request.rb
CHANGED
data/lib/yam/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -14,11 +14,13 @@
|
|
14
14
|
#
|
15
15
|
# See the Apache Version 2.0 License for specific language governing
|
16
16
|
# permissions and limitations under the License.
|
17
|
-
|
17
|
+
|
18
18
|
require 'simplecov'
|
19
|
+
|
19
20
|
SimpleCov.start do
|
20
21
|
add_filter 'spec'
|
21
22
|
end
|
23
|
+
|
22
24
|
require 'rspec'
|
23
25
|
require 'yam'
|
24
26
|
require 'webmock/rspec'
|
@@ -29,27 +31,12 @@ RSpec.configure do |config|
|
|
29
31
|
config.include WebMock::API
|
30
32
|
config.order = :rand
|
31
33
|
config.color_enabled = true
|
34
|
+
|
32
35
|
config.before(:each) do
|
33
36
|
Yam.set_defaults
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
37
|
-
def stub_post(path, endpoint = Yam.endpoint.to_s)
|
38
|
-
stub_request(:post, endpoint + path)
|
39
|
-
end
|
40
|
-
|
41
|
-
def stub_get(path, endpoint = Yam.endpoint.to_s)
|
42
|
-
stub_request(:get, endpoint + path)
|
43
|
-
end
|
44
|
-
|
45
|
-
def a_post(path, endpoint = Yam.endpoint.to_s)
|
46
|
-
a_request(:post, endpoint + path)
|
47
|
-
end
|
48
|
-
|
49
|
-
def a_get(path, endpoint = Yam.endpoint.to_s)
|
50
|
-
a_request(:get, endpoint + path)
|
51
|
-
end
|
52
|
-
|
53
40
|
def fixture_path
|
54
41
|
File.expand_path("../fixtures", __FILE__)
|
55
42
|
end
|
data/spec/yam/client_spec.rb
CHANGED
@@ -14,29 +14,30 @@
|
|
14
14
|
#
|
15
15
|
# See the Apache Version 2.0 License for specific language governing
|
16
16
|
# permissions and limitations under the License.
|
17
|
-
|
17
|
+
|
18
18
|
require 'spec_helper'
|
19
|
+
ENDPOINT = Yam::Configuration::DEFAULT_API_ENDPOINT
|
19
20
|
|
20
21
|
describe Yam::Client, '#get' do
|
21
22
|
it 'makes requests' do
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
stub_request(:get, ENDPOINT)
|
24
|
+
access_token = 'ABC123'
|
25
|
+
|
26
|
+
instance = Yam::Client.new(access_token, ENDPOINT)
|
27
|
+
instance.get('/')
|
28
|
+
|
29
|
+
expect(a_request(:get, ENDPOINT)).to have_been_made
|
25
30
|
end
|
26
31
|
end
|
27
32
|
|
28
33
|
describe Yam::Client, '#post' do
|
29
34
|
it 'makes requests' do
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
35
|
+
stub_request(:post, ENDPOINT)
|
36
|
+
access_token = 'ABC123'
|
37
|
+
|
38
|
+
instance = Yam::Client.new(access_token, ENDPOINT)
|
39
|
+
instance.post('/')
|
34
40
|
|
35
|
-
|
36
|
-
access_token = '123'
|
37
|
-
Yam.oauth_token = access_token
|
38
|
-
stub_post("/custom/post?access_token=#{access_token}")
|
39
|
-
subject.post('/custom/post')
|
40
|
-
expect(a_post("/custom/post?access_token=#{access_token}")).to have_been_made
|
41
|
+
expect(a_request(:post, ENDPOINT)).to have_been_made
|
41
42
|
end
|
42
43
|
end
|
data/spec/yam_spec.rb
CHANGED
@@ -14,87 +14,76 @@
|
|
14
14
|
#
|
15
15
|
# See the Apache Version 2.0 License for specific language governing
|
16
16
|
# permissions and limitations under the License.
|
17
|
-
|
17
|
+
|
18
18
|
require 'spec_helper'
|
19
|
+
|
19
20
|
class TestClass
|
20
21
|
end
|
22
|
+
|
21
23
|
describe Yam do
|
24
|
+
# after do
|
25
|
+
# Yam.set_defaults
|
26
|
+
# end
|
22
27
|
|
23
|
-
|
24
|
-
subject.set_defaults
|
25
|
-
end
|
28
|
+
ENDPOINT = Yam::Configuration::DEFAULT_API_ENDPOINT
|
26
29
|
|
27
30
|
it 'responds to \'new\' message' do
|
28
|
-
|
31
|
+
Yam.should respond_to :new
|
29
32
|
end
|
30
33
|
|
31
|
-
it 'receives \'new\' and initialize
|
32
|
-
|
34
|
+
it 'receives \'new\' and initialize an instance' do
|
35
|
+
access_token = 'ABC123'
|
36
|
+
|
37
|
+
instance = Yam.new(access_token, ENDPOINT)
|
38
|
+
|
39
|
+
instance.should be_a Yam::Client
|
33
40
|
end
|
34
41
|
|
35
42
|
it 'delegates to a Yam::Client instance' do
|
43
|
+
access_token = 'ABC123'
|
36
44
|
Yam::Client.any_instance.stubs(:stubbed_method)
|
37
45
|
|
38
|
-
Yam.
|
46
|
+
instance = Yam.new(access_token, ENDPOINT)
|
47
|
+
instance.stubbed_method
|
39
48
|
|
40
49
|
Yam::Client.any_instance.should have_received(:stubbed_method)
|
41
50
|
end
|
42
51
|
|
43
|
-
it 'responds to \'configure\' message' do
|
44
|
-
subject.should respond_to :configure
|
45
|
-
end
|
46
|
-
|
47
52
|
describe 'setting configuration options' do
|
48
53
|
it 'returns the default adapter' do
|
49
|
-
|
54
|
+
adapter = Yam.adapter
|
55
|
+
|
56
|
+
adapter.should == Yam::Configuration::DEFAULT_ADAPTER
|
50
57
|
end
|
51
58
|
|
52
59
|
it 'allows setting the adapter' do
|
53
|
-
|
54
|
-
|
60
|
+
Yam.adapter = :typhoeus
|
61
|
+
|
62
|
+
Yam.adapter.should == :typhoeus
|
55
63
|
end
|
56
64
|
|
57
65
|
it 'returns the default end point' do
|
58
|
-
|
66
|
+
Yam.endpoint.should == ENDPOINT
|
59
67
|
end
|
60
68
|
|
61
69
|
it 'allows setting the endpoint' do
|
62
|
-
|
63
|
-
|
70
|
+
Yam.endpoint = 'http://www.example.com'
|
71
|
+
Yam.endpoint.should == 'http://www.example.com'
|
64
72
|
end
|
65
73
|
|
66
74
|
it 'returns the default user agent' do
|
67
|
-
|
75
|
+
Yam.user_agent.should == Yam::Configuration::DEFAULT_USER_AGENT
|
68
76
|
end
|
69
77
|
|
70
78
|
it 'allows setting the user agent' do
|
71
|
-
|
72
|
-
subject.user_agent.should == 'New User Agent'
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'does not set oauth token' do
|
76
|
-
subject.oauth_token.should be_nil
|
77
|
-
end
|
79
|
+
Yam.user_agent = 'New User Agent'
|
78
80
|
|
79
|
-
|
80
|
-
subject.oauth_token = 'OT'
|
81
|
-
subject.oauth_token.should == 'OT'
|
81
|
+
Yam.user_agent.should == 'New User Agent'
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'allows setting the current api client' do
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe '.configure' do
|
91
|
-
Yam::Configuration::VALID_OPTIONS_KEYS.each do |key|
|
92
|
-
it "should set the #{key}" do
|
93
|
-
Yam.configure do |config|
|
94
|
-
config.send("#{key}=", key)
|
95
|
-
Yam.send(key).should == key
|
96
|
-
end
|
97
|
-
end
|
85
|
+
Yam.should respond_to :api_client=
|
86
|
+
Yam.should respond_to :api_client
|
98
87
|
end
|
99
88
|
end
|
100
89
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-12-
|
13
|
+
date: 2012-12-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: hashie
|