api-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@api_client
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - ree-1.8.7
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in api_client.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # ApiClient [![Build Status](https://secure.travis-ci.org/plribeiro3000/api_client.png)](http://travis-ci.org/plribeiro3000/api_client)
2
+
3
+ Client to make Api calls
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'api-client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install api-client
18
+
19
+ ## Usage
20
+
21
+ Add this to your ApplicationController:
22
+
23
+ rescue_from ApiClient::Exceptions::NotFound, :with => :not_found
24
+
25
+ def not_found
26
+ #Specify your own behavior here
27
+ end
28
+
29
+ Then, on your action, just put into it:
30
+
31
+ @user = ApiClient.get("http://api.example.com/user/3")
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc "Default Task"
8
+ task :default => [ :spec ]
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/api_client/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "api-client"
6
+ gem.version = ApiClient::VERSION
7
+ gem.authors = %q{Paulo Henrique Lopes Ribeiro}
8
+ gem.email = %q{plribeiro3000@gmail.com}
9
+ gem.homepage = ""
10
+ gem.summary = %q{Client to make Api calls}
11
+
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ gem.require_paths = %w(lib)
16
+
17
+ gem.add_development_dependency "rake"
18
+ gem.add_development_dependency "fakeweb"
19
+ gem.add_development_dependency "rspec", "2.9.0"
20
+ end
data/lib/api_client.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "api_client/version"
2
+ require "net/http"
3
+
4
+ module ApiClient
5
+ autoload :Exceptions, 'api_client/exceptions'
6
+
7
+ def self.get(url)
8
+ response = Net::HTTP.get_response(URI.parse(url))
9
+ raise ApiClient::Exceptions::NotFound if response.code == '404'
10
+ response.body
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module ApiClient::Exceptions
2
+ autoload :NotFound, 'api_client/exceptions/not_found'
3
+ end
@@ -0,0 +1,5 @@
1
+ class ApiClient::Exceptions::NotFound < StandardError
2
+ def initialize
3
+ super("The required url could not be found!")
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module ApiClient
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe ApiClient do
4
+ describe "#get" do
5
+ context "when response code is 404" do
6
+ before :each do
7
+ FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "404")
8
+ end
9
+
10
+ it "should return a NotFound exception" do
11
+ lambda { ApiClient.get('http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::NotFound)
12
+ end
13
+ end
14
+
15
+ context "when response code is not 404" do
16
+ before :each do
17
+ FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "201", :body => "User#3333")
18
+ end
19
+
20
+ it "should return the response body" do
21
+ ApiClient.get('http://api.example.com/user/5').should == "User#3333"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ require "rspec"
2
+ require "fakeweb"
3
+
4
+ require File.dirname(__FILE__) + "/../lib/api_client"
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: api-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Paulo Henrique Lopes Ribeiro
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fakeweb
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: 2.9.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.9.0
62
+ description:
63
+ email: plribeiro3000@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - .gitignore
69
+ - .rspec
70
+ - .rvmrc
71
+ - .travis.yml
72
+ - Gemfile
73
+ - LICENSE
74
+ - README.md
75
+ - Rakefile
76
+ - api_client.gemspec
77
+ - lib/api_client.rb
78
+ - lib/api_client/exceptions.rb
79
+ - lib/api_client/exceptions/not_found.rb
80
+ - lib/api_client/version.rb
81
+ - spec/api_client_spec.rb
82
+ - spec/spec_helper.rb
83
+ homepage: ''
84
+ licenses: []
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ segments:
96
+ - 0
97
+ hash: -173903342828819103
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ segments:
105
+ - 0
106
+ hash: -173903342828819103
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 1.8.24
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Client to make Api calls
113
+ test_files: []