api-client 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,9 +4,15 @@ require "net/http"
4
4
  module ApiClient
5
5
  autoload :Exceptions, 'api_client/exceptions'
6
6
 
7
- def self.get(url)
7
+ def self.get(url = '')
8
8
  response = Net::HTTP.get_response(URI.parse(url))
9
9
  raise ApiClient::Exceptions::NotFound if response.code == '404'
10
10
  response.body
11
11
  end
12
+
13
+ def self.post(url = '', args = {})
14
+ response = Net::HTTP.post_form(URI.parse(url), args)
15
+ raise ApiClient::Exceptions::NotFound if response.code == '404'
16
+ response.body
17
+ end
12
18
  end
@@ -1,5 +1,5 @@
1
1
  class ApiClient::Exceptions::Generic < StandardError
2
- def initialize
2
+ def self.initialize
3
3
  super("An Error Occurred!")
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  class ApiClient::Exceptions::NotFound < ApiClient::Exceptions::Generic
2
- def initialize
2
+ def self.initialize
3
3
  super("The required url could not be found!")
4
4
  end
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module ApiClient
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -22,4 +22,26 @@ describe ApiClient do
22
22
  end
23
23
  end
24
24
  end
25
+
26
+ describe "#post" do
27
+ context "when response code is 404" do
28
+ before :each do
29
+ FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "404")
30
+ end
31
+
32
+ it "should return a NotFound exception" do
33
+ lambda { ApiClient.post('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::NotFound)
34
+ end
35
+ end
36
+
37
+ context "when response code is not 404" do
38
+ before :each do
39
+ FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "201", :body => "User#3333")
40
+ end
41
+
42
+ it "should return the response body" do
43
+ ApiClient.post('http://api.example.com/user/5', {}).should == "User#3333"
44
+ end
45
+ end
46
+ end
25
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -95,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  segments:
97
97
  - 0
98
- hash: 3823240331575082275
98
+ hash: 343196442322712530
99
99
  required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  none: false
101
101
  requirements:
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  version: '0'
105
105
  segments:
106
106
  - 0
107
- hash: 3823240331575082275
107
+ hash: 343196442322712530
108
108
  requirements: []
109
109
  rubyforge_project:
110
110
  rubygems_version: 1.8.24