client 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e5ccace8cea9232907b87fdf819d33a816efd29
4
- data.tar.gz: 8ba1b52535e868b6cf43b449220dfa24dc2e7a1b
3
+ metadata.gz: dd0537dc74943e0bf99d8055ca8952945bd911a8
4
+ data.tar.gz: ef5e10a90e36fc38bbdc1ce93c8c306a8e3e655d
5
5
  SHA512:
6
- metadata.gz: 3095f3f24073ae5923b1815be9cc880ac61cc200f117be0c4218859067f562047c456d092835af0f0be5df0dd56bf6dac127af6bb1f0224d1345902f646782ca
7
- data.tar.gz: 7d092e62613ed3a0869b9bb986d982427d27cff50e863920bf0f56c782edb3d9ed7f0a1640f019dac7256bca85e6fe141cf26573498b32ac4a0ac796851a0894
6
+ metadata.gz: 5350cf7f71f42706edbeea7b21c088ba159586d54221d9996d8af67b692ccdd62891bdc9647d61a46fd1a16912c1259a0d8c0d5c669a0b14acb48bcfede30895
7
+ data.tar.gz: 159ffde0117c95141339244e4aa36baa7a1b4c29cd165a5706eeed5fcdab41637591071fa655b84a7e5b9fdf0f868b2c747af4f7d14029778716f006a590a2f9
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/README.md CHANGED
@@ -1,24 +1,49 @@
1
1
  # Client
2
+ [![Build Status](https://travis-ci.org/bonzofenix/client.png)](https://travis-ci.org/bonzofenix/client)
2
3
 
3
- TODO: Write a gem description
4
+ Client provides you with metaprogram ruby rest clients generated from yml configurations.
4
5
 
5
6
  ## Installation
6
7
 
7
8
  Add this line to your application's Gemfile:
8
9
 
9
10
  gem 'client'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install client
11
+
12
+ and run `bundle`
18
13
 
19
14
  ## Usage
20
-
21
- TODO: Write usage instructions here
15
+ Client tries to generate res clients at soon as you require the gem.
16
+ It will try to find `client.yml` in the main folder of your project:
17
+
18
+ /my_project/client.yml
19
+
20
+ The yaml should look something like this:
21
+
22
+ ```yml
23
+ google:
24
+ endpoint: 'http://www.google.com'
25
+ ```
26
+
27
+ This will generate a rest client for you to perform post and gets and return NET/http responses:
28
+
29
+ ```ruby
30
+ require 'client'
31
+ Client::Google.get 'search', {q: 'bonzofenix gem client'}
32
+ #This should perform a GET to http://www.google.com/search?q=bonzofenix+gem+client
33
+ ```
34
+
35
+ You can also load specific yml files:
36
+
37
+ ```ruby
38
+ require 'client'
39
+ Client.load_clients 'config/twitter.yml', 'config/google.yml'
40
+ Client::Twitter
41
+ # => Client::Twitter
42
+ Client::Google
43
+ # => Client::Google
44
+ ```
45
+
46
+ See the spec folder for more examples.
22
47
 
23
48
  ## Contributing
24
49
 
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -1,3 +1,3 @@
1
1
  class Client
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
data/lib/client.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'client/version'
2
2
  require 'net/http'
3
+ require 'logger'
3
4
  require 'yaml'
4
5
 
5
6
  class String
@@ -21,28 +22,42 @@ end
21
22
  class Client
22
23
  class Base
23
24
  class << self
24
- def endpoint= (endpoint)
25
- @endpoint = endpoint
26
- end
27
-
28
- def endpoint
29
- @endpoint
25
+ attr_accessor :endpoint
26
+ def perform(method, resource, params)
27
+ uri = URI("#{endpoint}/#{resource}")
28
+ case method
29
+ when :get
30
+ uri.query = URI.encode_www_form(params) if params
31
+ Net::HTTP.get_response(uri)
32
+ when :post
33
+ Net::HTTP.post_form(uri, params)
34
+ end.tap do |r|
35
+ logger.info "Client::Base performed: #{method} to #{uri.to_s} \
36
+ params: #{params} got: #{r.inspect} code: #{r.code}"
37
+ end
30
38
  end
31
39
 
32
40
  def post(resource, params)
33
- uri = URI("#{endpoint}/#{resource}")
34
- Net::HTTP.post_form(uri, params)
41
+ perform(:post,resource, params)
35
42
  end
36
43
 
37
44
  def get(resource, params = nil)
38
- uri = URI("#{endpoint}/#{resource}")
39
- uri.query = URI.encode_www_form(params) if params
40
- Net::HTTP.get_response(uri)
45
+ perform(:get ,resource, params)
46
+ end
47
+
48
+ def logger
49
+ Client.logger
41
50
  end
42
51
  end
43
52
  end
44
53
 
45
54
  class << self
55
+ attr_accessor :logger
56
+
57
+ def logger
58
+ @logger ||= Logger.new(STDOUT).tap{ |l| l.level = Logger::WARN }
59
+ end
60
+
46
61
  def clients
47
62
  @clients ||= {}
48
63
  end
@@ -11,9 +11,6 @@ describe Client do
11
11
  Client.load_clients("#{Dir.pwd}/twitter.yml")
12
12
  end
13
13
 
14
- describe '#load_clients' do
15
- it 'warns when it can fine the file'
16
- end
17
14
 
18
15
  it 'creates a subclass' do
19
16
  Client::Twitter.should be
@@ -35,4 +32,9 @@ describe Client do
35
32
  WebMock.should have_requested(:get, 'http://twitter.com/tweet?id=10')
36
33
  end
37
34
  end
35
+
36
+
37
+ describe 'when loading config files manually' do
38
+ it 'warns when it can fine the file'
39
+ end
38
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
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-18 00:00:00.000000000 Z
11
+ date: 2013-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,6 +75,7 @@ extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - .gitignore
78
+ - .travis.yml
78
79
  - Gemfile
79
80
  - LICENSE.txt
80
81
  - README.md