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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1a22924ee52be73baa2a86212d971f97add0993
4
- data.tar.gz: 9dc4fa909a087f5c785baa609ab301b54ddb3175
3
+ metadata.gz: 1f0806c66e3ad5ab1ce9c8c13a33ba927a00330a
4
+ data.tar.gz: b2024bbac90d6877f7ce912b78d26af8ef4ba6c7
5
5
  SHA512:
6
- metadata.gz: f71960a3f7a8cf0a6506db64c88263732720d69bf00a3e6bd68c34848944bf1d1f8c4f2bb3a5c6558548cd8d66fa38a640837b5bebf997e4c37c307ddaa3ef01
7
- data.tar.gz: e935b71d0c20f6cb864b698c4ff36e7eee6512668f4244407a91c2c153b2739080fecc8f82a4ef6e98c35a5757ba43d960a281ef2e78ae0c14549b86c7263bf6
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", "~> 1.3"
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
@@ -1,3 +1,3 @@
1
1
  class Client
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/client.rb CHANGED
@@ -1,4 +1,5 @@
1
- require "client/version"
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
- def self.clients
45
- YAML.load_file("client.yml")
46
- end
45
+ class << self
46
+ def clients
47
+ @clients ||= {}
48
+ end
47
49
 
48
- # begin
49
- clients.each do |name, info|
50
- Class.new(Base) do
51
- self.endpoint= info.fetch('endpoint')
52
- end.tap do |client_class|
53
- const_set(name.camelize, client_class)
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
- def self.gitlab(method, resource, params ={}, opts = nil)
69
- uri = URI("https://gitlab.com/api/v3/#{resource}")
70
- res = if method == :get
71
- uri.query = URI.encode_www_form(params)
72
- Net::HTTP.get_response(uri)
73
- else
74
- Net::HTTP.post_form(uri, params)
75
- end
76
- res
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
 
@@ -1,10 +1,36 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Client do
4
- let(:client){ described_class }
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
- describe 'when there is a config' do
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
@@ -0,0 +1,2 @@
1
+ twitter:
2
+ endpoint: http://twitter.com
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,8 @@
1
- require 'bundle/setup'
1
+ require 'bundler/setup'
2
+ require 'webmock/rspec'
2
3
  require 'client'
3
4
 
4
5
 
5
- Rspec.configure do |config|
6
+ RSpec.configure do |config|
6
7
  end
7
8
 
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.2
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-15 00:00:00.000000000 Z
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: '1.3'
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: '1.3'
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