client 0.0.5 → 0.0.6
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/.rspec +4 -0
- data/client.gemspec +1 -0
- data/lib/client.rb +34 -6
- data/lib/client/version.rb +1 -1
- data/spec/client/client_spec.rb +14 -5
- data/spec/fixtures/twitter.yml +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eba14d73f113db9db150c478566abb59ac2c4905
|
4
|
+
data.tar.gz: bdc321714d4c6baed1a846c8ac07585486f52117
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce3bc4a69a7eed6c62a7352419c5945bd35e4734f6ea2da1943d48b680d4d190105c5209e171e37118b7632c1ae74084aef2bc51d15f843bed679472f8f040e0
|
7
|
+
data.tar.gz: 3cba3ac3957b1b932d2fdfd132b6876332b8b34117dc9b793b39e80c1f526f6e278fedc4a4d845599ae60974cff5016c0858193edfffd98d105a52dbee8340d3
|
data/.rspec
ADDED
data/client.gemspec
CHANGED
@@ -18,6 +18,7 @@ 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_dependency "httparty"
|
21
22
|
spec.add_development_dependency "bundler"
|
22
23
|
spec.add_development_dependency "rake"
|
23
24
|
spec.add_development_dependency "rspec"
|
data/lib/client.rb
CHANGED
@@ -23,14 +23,15 @@ class Client
|
|
23
23
|
class Base
|
24
24
|
class << self
|
25
25
|
attr_accessor :endpoint
|
26
|
-
|
27
|
-
|
26
|
+
|
27
|
+
def perform(method, resource, params = nil)
|
28
28
|
case method
|
29
29
|
when :get
|
30
|
-
|
31
|
-
Net::HTTP.get_response(uri)
|
30
|
+
api.get(resource)
|
32
31
|
when :post
|
33
|
-
|
32
|
+
api.post(resource, www_params)
|
33
|
+
when :delete
|
34
|
+
api.delete(resource)
|
34
35
|
end.tap do |r|
|
35
36
|
logger.info "Client::Base performed: #{method} to #{uri.to_s} \
|
36
37
|
params: #{params} got: #{r.inspect} code: #{r.code}"
|
@@ -38,7 +39,8 @@ class Client
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def post(resource, params)
|
41
|
-
|
42
|
+
@params = params
|
43
|
+
perform(:post, resource)
|
42
44
|
end
|
43
45
|
|
44
46
|
def get(resource, params = nil)
|
@@ -48,6 +50,32 @@ class Client
|
|
48
50
|
def logger
|
49
51
|
Client.logger
|
50
52
|
end
|
53
|
+
|
54
|
+
def method_missing(m, *args, &block)
|
55
|
+
action, path = m.to_s.match(/(^[^_]+(?=_))_(.+)/).captures
|
56
|
+
@params = args.first
|
57
|
+
case action
|
58
|
+
when *%w{find list}
|
59
|
+
perform(:get, "/#{path}?#{www_params}")
|
60
|
+
when *%w{delete remove destroy}
|
61
|
+
perform(:delete, "/#{path}/#{@params}")
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def www_params
|
70
|
+
URI.encode_www_form(@params) if @params
|
71
|
+
end
|
72
|
+
def uri
|
73
|
+
URI(endpoint)
|
74
|
+
end
|
75
|
+
|
76
|
+
def api
|
77
|
+
Net::HTTP.new(uri)
|
78
|
+
end
|
51
79
|
end
|
52
80
|
end
|
53
81
|
|
data/lib/client/version.rb
CHANGED
data/spec/client/client_spec.rb
CHANGED
@@ -17,19 +17,28 @@ describe Client do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'perform a post' do
|
20
|
-
Client::Twitter.post('tweet', {id: '1', text: 'wtf'})
|
20
|
+
Client::Twitter.post('/tweet', {id: '1', text: 'wtf'})
|
21
21
|
WebMock.should have_requested(:post, 'http://twitter.com/tweet')
|
22
22
|
.with { |req| req.body == 'id=1&text=wtf' }
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'perform a get' do
|
26
|
-
Client::Twitter.get('tweet')
|
26
|
+
Client::Twitter.get('/tweet')
|
27
27
|
WebMock.should have_requested(:get, 'http://twitter.com/tweet')
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
%w{find list}.each do |action|
|
31
|
+
it "perform a get with params for #{action}" do
|
32
|
+
Client::Twitter.send("#{action}_tweet", {id: 10})
|
33
|
+
WebMock.should have_requested(:get, 'http://twitter.com/tweet?id=10')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
%w{delete remove destroy}.each do |action|
|
38
|
+
it "perform a delete with the params for #{action}" do
|
39
|
+
Client::Twitter.send("#{action}_tweet", 1)
|
40
|
+
WebMock.should have_requested(:delete, 'http://twitter.com/tweet/1')
|
41
|
+
end
|
33
42
|
end
|
34
43
|
end
|
35
44
|
|
data/spec/fixtures/twitter.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
twitter:
|
2
|
-
endpoint:
|
2
|
+
endpoint: twitter.com
|
metadata
CHANGED
@@ -1,15 +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.6
|
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
|
+
date: 2013-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
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'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,6 +89,7 @@ extensions: []
|
|
75
89
|
extra_rdoc_files: []
|
76
90
|
files:
|
77
91
|
- .gitignore
|
92
|
+
- .rspec
|
78
93
|
- .travis.yml
|
79
94
|
- Gemfile
|
80
95
|
- LICENSE.txt
|