paper-cup 0.1.1 → 0.1.2
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 +4 -4
- data/.travis.yml +12 -0
- data/README.md +19 -4
- data/Rakefile +10 -0
- data/lib/paper_cup/response.rb +3 -3
- data/paper-cup.gemspec +2 -1
- data/test/paper_cup_test.rb +2 -2
- data/test/paper_cup_test/response_test.rb +1 -1
- metadata +17 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6156fc04976c406a46b84b646cdc3f975b4c53e9
|
4
|
+
data.tar.gz: 40c7abe81e80b6934f1906f30ebd209fbfd7c704
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fed562528e8e17efda88a0ee1ccb92f8a444feab8776c6d8680125281beeb92fe07373b285a490332b44329cd65bf517ab7fc20347591ed2271f69915eb5798e
|
7
|
+
data.tar.gz: 75a5813a7847d2eae1a5f1df5b3d1b3c5412ee096a02e1107b29345d0d6c0413c27017927d4c2fb4c0835d884f9d2dc2d4dba706f827757c5c93be89ffc6ccb8
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# PaperCup
|
2
|
+
|
3
|
+

|
4
|
+
|
1
5
|
Instalation
|
2
6
|
----
|
3
7
|
|
@@ -11,7 +15,18 @@ None!!! Yeaaaah!
|
|
11
15
|
Usage
|
12
16
|
-----
|
13
17
|
|
14
|
-
At the moment it only works for `POSTs`, `GETs` and `PUTs`. If the
|
18
|
+
At the moment it only works for `POSTs`, `HEAD`s, `GETs` and `PUTs`. If the response is a JSON the gem will parse it, if not it will show as it cames
|
19
|
+
|
20
|
+
PaperCup only has these 4 methods: `#get`, `#head`, `#post` and `#put`.
|
21
|
+
|
22
|
+
For all the methods it accepts the next parameters:
|
23
|
+
|
24
|
+
* url: is mandatory
|
25
|
+
* headers: optional, it has to be a hash. Example: `{ "Content-Type" => "application/json"}`
|
26
|
+
* params: optional, same as the header. Example: { name: "Goku", race: "Saiyan" }
|
27
|
+
* body: optional, the body will be inserted with the [`-d`](http://curl.haxx.se/docs/manpage.html#-d) option of curl as it come.
|
28
|
+
|
29
|
+
All the method returns a [`Response`](https://github.com/casapick/paper-cup/blob/master/lib/paper_cup/response.rb) object, that has two attributes status and body. The status is the status code of the respond and the body is the response.
|
15
30
|
|
16
31
|
GET
|
17
32
|
----
|
@@ -21,7 +36,7 @@ GET
|
|
21
36
|
POST - PUT
|
22
37
|
----------
|
23
38
|
|
24
|
-
`PaperCup.post(url: url,
|
39
|
+
`PaperCup.post(url: url, params: {name: 'pepe'}, headers: { "Content-Type" => "application/json"})`
|
25
40
|
|
26
41
|
|
27
42
|
Response
|
@@ -31,7 +46,7 @@ Each request will return a `Response` object.
|
|
31
46
|
Example:
|
32
47
|
|
33
48
|
```ruby
|
34
|
-
r = PaperCup.post(url, some_hash.to_json)
|
35
|
-
puts r.
|
49
|
+
r = PaperCup.post(url, body: some_hash.to_json, headers: { "Content-Type" => "application/json"})
|
50
|
+
puts r.body # It will print the response returned by the endpoint
|
36
51
|
puts r.status # It will print the status code returned by the endpoint
|
37
52
|
```
|
data/Rakefile
ADDED
data/lib/paper_cup/response.rb
CHANGED
@@ -3,14 +3,14 @@ require_relative 'utils'
|
|
3
3
|
|
4
4
|
module PaperCup
|
5
5
|
class Response
|
6
|
-
attr_accessor :status, :
|
6
|
+
attr_accessor :status, :body
|
7
7
|
|
8
8
|
def initialize(raw_response)
|
9
9
|
@raw_response = raw_response
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
@
|
12
|
+
def body
|
13
|
+
@body ||= begin
|
14
14
|
str = @raw_response[0..-4]
|
15
15
|
PaperCup.valid_json?(str) ? JSON.parse(str) : str
|
16
16
|
end
|
data/paper-cup.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.platform = Gem::Platform::RUBY
|
3
3
|
s.name = 'paper-cup'
|
4
|
-
s.version = '0.1.
|
4
|
+
s.version = '0.1.2'
|
5
5
|
s.date = '2015-08-05'
|
6
6
|
s.summary = "Use of Open3 to make request"
|
7
7
|
s.description = "Use curl with Open3 for making request"
|
@@ -15,4 +15,5 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.add_development_dependency "minitest", '~> 5.8.0'
|
16
16
|
s.add_development_dependency "minitest-happy", '~> 1.0.0'
|
17
17
|
s.add_development_dependency "pry", '~> 0.10.1'
|
18
|
+
s.add_development_dependency "rake", '~> 10.4.2'
|
18
19
|
end
|
data/test/paper_cup_test.rb
CHANGED
@@ -7,7 +7,7 @@ describe PaperCup do
|
|
7
7
|
it "must parse the response" do
|
8
8
|
Open3.stub :capture3, [Mock.json] do # stub goes away once the block is done
|
9
9
|
r = PaperCup.get("http://www.google.com")
|
10
|
-
assert_equal "Rails", r.
|
10
|
+
assert_equal "Rails", r.body.first["framework"], "The framework must be rails"
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -15,7 +15,7 @@ describe PaperCup do
|
|
15
15
|
it "must set the response as it come" do
|
16
16
|
Open3.stub :capture3, [Mock.html] do # stub goes away once the block is done
|
17
17
|
r = PaperCup.get("http://www.google.com")
|
18
|
-
assert_equal Mock.html, "#{r.
|
18
|
+
assert_equal Mock.html, "#{r.body}#{r.status}", "The response must be the same"
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -17,7 +17,7 @@ describe PaperCup::Response do
|
|
17
17
|
describe "when the response is a JSON" do
|
18
18
|
it "must set the response properly" do
|
19
19
|
r = PaperCup::Response.new(Mock.json)
|
20
|
-
assert_equal JSON.parse(Mock.json[0..-4]), r.
|
20
|
+
assert_equal JSON.parse(Mock.json[0..-4]), r.body
|
21
21
|
end
|
22
22
|
|
23
23
|
it "must set the status code response properly" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paper-cup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mariano Matayoshi
|
@@ -54,6 +54,20 @@ dependencies:
|
|
54
54
|
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: 0.10.1
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: rake
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 10.4.2
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 10.4.2
|
57
71
|
description: Use curl with Open3 for making request
|
58
72
|
email: matayoshi.mariano@gmail.com
|
59
73
|
executables: []
|
@@ -61,8 +75,10 @@ extensions: []
|
|
61
75
|
extra_rdoc_files: []
|
62
76
|
files:
|
63
77
|
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
64
79
|
- Gemfile
|
65
80
|
- README.md
|
81
|
+
- Rakefile
|
66
82
|
- lib/paper_cup.rb
|
67
83
|
- lib/paper_cup/request.rb
|
68
84
|
- lib/paper_cup/response.rb
|