client 0.0.7 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d902e6cc8f1fc09b8bc03c1686c741c23fe82fa8
4
- data.tar.gz: a180e712414555650e2ba56afb0fa78073d9a5ef
3
+ metadata.gz: a59fea54a5a4afd0fa732219a662e8f550766740
4
+ data.tar.gz: 798ff068cf67053d0f0238ae13777e08d453c261
5
5
  SHA512:
6
- metadata.gz: eb1fbd425455a311343c5b472351c2b45cc26b0f28cd4e5b24a9269574a2fdafe5eb05b29b5fc8c6b53075685d93e6af793ebaac8da427bdd2c99ec382871b97
7
- data.tar.gz: 092d2c47fb15a752480e7f768fa7e4fd507076d6a36e230f83bed5a40bd7d9b0103edfd40c56ccc80b03cdcaed5cf08f170c0fd13632f4d543132af86fd37d15
6
+ metadata.gz: 9e058240202a995825a808662bf6b9f00b511f59912fc7091b5c15e45bb3b7c7b08ad0ea60a3828519e0f2c8b8612bc5805fffcc51104be72c7b98221d540b60
7
+ data.tar.gz: aeec1d1a72f9b52914cbe836f56eab9cc6b156f634294d090dc6fff4a0a080e446a79e0cf10048755da51a5c9958f50ba931997c7538af6238d3780600416d39
data/client.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "httparty"
22
+ spec.add_dependency 'recursive-open-struct'
22
23
  spec.add_development_dependency "bundler"
23
24
  spec.add_development_dependency "rake"
24
25
  spec.add_development_dependency "rspec"
data/lib/client.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'client/version'
2
2
  require 'net/http'
3
3
  require 'httparty'
4
+ require 'recursive-open-struct'
5
+ require 'json'
4
6
  require 'logger'
5
7
  require 'yaml'
6
8
 
@@ -19,6 +21,20 @@ class String
19
21
  end
20
22
  end
21
23
 
24
+ class HTTParty::Response
25
+ def json
26
+ ::JSON.parse(self.body)
27
+ end
28
+
29
+ def struct
30
+ case json
31
+ when ::Array
32
+ json.map{|o| ::RecursiveOpenStruct.new o, recurse_over_arrays: true }
33
+ when ::Hash
34
+ ::RecursiveOpenStruct.new json, recurse_over_arrays: true
35
+ end
36
+ end
37
+ end
22
38
 
23
39
  class Client
24
40
  class Base
@@ -27,14 +43,16 @@ class Client
27
43
  # params: #{params} got: #{r.inspect} code: #{r.code}"
28
44
 
29
45
  def method_missing(m, *args, &block)
30
- warn m
31
46
  action, path = m.to_s.match(/(^[^_]+(?=_))_(.+)/).captures
32
- params = args.first
47
+ params , body = *args[0..1]
48
+ warn params
33
49
  case action
34
50
  when *%w{find list}
35
51
  self.get("/#{path}", query: params )
36
52
  when *%w{delete remove destroy}
37
- self.delete("/#{path}/#{params}")
53
+ self.delete("/#{path}/#{params}", body: body)
54
+ when *%w{post create}
55
+ self.post("/#{path}",body: params)
38
56
  end
39
57
  end
40
58
  end
@@ -1,3 +1,3 @@
1
1
  class Client
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -11,13 +11,12 @@ describe Client do
11
11
  Client.load_clients("#{Dir.pwd}/twitter.yml")
12
12
  end
13
13
 
14
-
15
14
  it 'creates a subclass' do
16
15
  Client::Twitter.should be
17
16
  end
18
17
 
19
18
  it 'perform a post' do
20
- Client::Twitter.post('/tweet',body: {id: '1', text: 'wtf'})
19
+ Client::Twitter.post_tweet(id: '1', text: 'wtf')
21
20
  WebMock.should have_requested(:post, 'http://twitter.com/tweet')
22
21
  .with { |req| req.body == 'id=1&text=wtf' }
23
22
  end
@@ -33,6 +32,7 @@ describe Client do
33
32
  WebMock.should have_requested(:get, 'http://twitter.com/tweet')
34
33
  end
35
34
 
35
+
36
36
  %w{find list}.each do |action|
37
37
  it "perform a get with params for #{action}" do
38
38
  Client::Twitter.send("#{action}_tweet", {id: 10})
@@ -41,15 +41,25 @@ describe Client do
41
41
  end
42
42
 
43
43
  %w{delete remove destroy}.each do |action|
44
- it "perform a delete with params for #{action}" do
44
+ it "perform a delete with id for #{action}" do
45
45
  Client::Twitter.send("#{action}_tweet", 1)
46
46
  WebMock.should have_requested(:delete, 'http://twitter.com/tweet/1')
47
47
  end
48
+
49
+ it "perform a delete with params and id for #{action}" do
50
+ Client::Twitter.send("#{action}_tweet", 1, {token: 1234})
51
+ WebMock.should have_requested(:delete, 'http://twitter.com/tweet/1')
52
+ .with { |req| req.body == 'token=1234' }
53
+
54
+ end
48
55
  end
56
+
49
57
  end
50
58
 
51
59
 
52
60
  describe 'when loading config files manually' do
53
61
  it 'warns when it can fine the file'
54
62
  end
63
+ it 'returns struct'
64
+ it 'returns json'
55
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - bonzofenix
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: recursive-open-struct
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'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement