client 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/client.gemspec +3 -1
- data/lib/client/version.rb +1 -1
- data/lib/client.rb +30 -32
- data/spec/client/client_spec.rb +28 -2
- data/spec/fixtures/twitter.yml +2 -0
- data/spec/spec_helper.rb +3 -2
- metadata +36 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f0806c66e3ad5ab1ce9c8c13a33ba927a00330a
|
4
|
+
data.tar.gz: b2024bbac90d6877f7ce912b78d26af8ef4ba6c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b9705290c64b92bd2c18f3accf23d6a9c354af47d22b92f1f40eba243c3f32a92f18072062945ab85516ecd84f2c855549f8225a9349e7474aaf4727c1e3354
|
7
|
+
data.tar.gz: 34f1574ebdca6336fca4f71effd5d091dd910d0ba4cf47d2492ec8252c0fad521f3a2fc6c534bab7ff0f0649ee295a7ca5d0bc90d6c3a0ace363c59bcdbed5cd
|
data/client.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler"
|
21
|
+
spec.add_development_dependency "bundler"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "webmock"
|
23
25
|
end
|
data/lib/client/version.rb
CHANGED
data/lib/client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require
|
1
|
+
require 'client/version'
|
2
|
+
require 'net/http'
|
2
3
|
require 'yaml'
|
3
4
|
|
4
5
|
class String
|
@@ -33,47 +34,44 @@ class Client
|
|
33
34
|
Net::HTTP.post_form(uri, params)
|
34
35
|
end
|
35
36
|
|
36
|
-
def get(resource, params)
|
37
|
+
def get(resource, params = nil)
|
37
38
|
uri = URI("#{endpoint}/#{resource}")
|
38
|
-
uri.query = URI.encode_www_form(params)
|
39
|
+
uri.query = URI.encode_www_form(params) if params
|
39
40
|
Net::HTTP.get_response(uri)
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
class << self
|
46
|
+
def clients
|
47
|
+
@clients ||= {}
|
48
|
+
end
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
def load_clients(path = 'client.yml')
|
51
|
+
begin
|
52
|
+
clients.merge! YAML.load_file(path)
|
53
|
+
rescue
|
54
|
+
warn '''Check that you have an client.env file in your project with
|
55
|
+
the following entry.
|
56
|
+
gitlab:
|
57
|
+
endpoint: http://gitlab.com/api/v3/
|
58
|
+
other_server:
|
59
|
+
endpoint: other_endpoint.com
|
60
|
+
'''
|
61
|
+
{}
|
54
62
|
end
|
55
63
|
end
|
56
|
-
# rescue
|
57
|
-
# puts $@
|
58
|
-
# warn '''Check that you have an client.env file in your project with
|
59
|
-
# the following entry.
|
60
|
-
# gitlab:
|
61
|
-
# endpoint: http://gitlab.com/api/v3/
|
62
|
-
# other_server:
|
63
|
-
# endpoint: other_endpoint.com
|
64
|
-
# '''
|
65
|
-
# end
|
66
|
-
|
67
64
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
65
|
+
def init
|
66
|
+
load_clients if clients.empty?
|
67
|
+
clients.each do |name, info|
|
68
|
+
Class.new(Base) do
|
69
|
+
self.endpoint = info.fetch('endpoint')
|
70
|
+
end.tap do |client_class|
|
71
|
+
const_set(name.camelize, client_class)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
77
75
|
end
|
78
76
|
end
|
79
77
|
|
data/spec/client/client_spec.rb
CHANGED
@@ -1,10 +1,36 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Client do
|
4
|
-
|
4
|
+
describe 'when there is a config' do
|
5
|
+
before do
|
6
|
+
stub_request(:any, /.*twitter.*/)
|
7
|
+
Client.load_clients(File.expand_path('../fixtures/twitter.yml',
|
8
|
+
File.dirname(__FILE__)))
|
9
|
+
Client.init
|
10
|
+
end
|
5
11
|
|
12
|
+
describe '#load_clients' do
|
13
|
+
it 'warns when it can fine the file'
|
14
|
+
end
|
6
15
|
|
7
|
-
|
16
|
+
it 'creates a subclass' do
|
17
|
+
Client::Twitter.should be
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'perform a post' do
|
21
|
+
Client::Twitter.post('tweet', {id: '1', text: 'wtf'})
|
22
|
+
WebMock.should have_requested(:post, 'http://twitter.com/tweet')
|
23
|
+
.with { |req| req.body == 'id=1&text=wtf' }
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'perform a get' do
|
27
|
+
Client::Twitter.get('tweet')
|
28
|
+
WebMock.should have_requested(:get, 'http://twitter.com/tweet')
|
29
|
+
end
|
8
30
|
|
31
|
+
it 'perform a get with params' do
|
32
|
+
Client::Twitter.get('tweet', {id: 10})
|
33
|
+
WebMock.should have_requested(:get, 'http://twitter.com/tweet?id=10')
|
34
|
+
end
|
9
35
|
end
|
10
36
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bonzofenix
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
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: webmock
|
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'
|
41
69
|
description: Client gives you the possibility to hit rest endpoints in an elegant
|
42
70
|
way
|
43
71
|
email:
|
@@ -55,6 +83,7 @@ files:
|
|
55
83
|
- lib/client.rb
|
56
84
|
- lib/client/version.rb
|
57
85
|
- spec/client/client_spec.rb
|
86
|
+
- spec/fixtures/twitter.yml
|
58
87
|
- spec/spec_helper.rb
|
59
88
|
homepage: ''
|
60
89
|
licenses:
|
@@ -82,4 +111,5 @@ specification_version: 4
|
|
82
111
|
summary: solves rest comunications
|
83
112
|
test_files:
|
84
113
|
- spec/client/client_spec.rb
|
114
|
+
- spec/fixtures/twitter.yml
|
85
115
|
- spec/spec_helper.rb
|