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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c054ba7ea95a3cfa40854c40bab74792c382357f
4
- data.tar.gz: 227b099b1929205290b9c7be3b626fb9fb624d5d
3
+ metadata.gz: 6156fc04976c406a46b84b646cdc3f975b4c53e9
4
+ data.tar.gz: 40c7abe81e80b6934f1906f30ebd209fbfd7c704
5
5
  SHA512:
6
- metadata.gz: 14361cf1f1b3ee531b61a934eb05244b76905fb43ddc53b18ea38cf5e69b2d838022ba824980a7f41c29907dd50423a293fa21f26b85f7677b14b32e030f1f2d
7
- data.tar.gz: a1c986904938cefe659eff2a214b20ecb78e2489ff337f3f9e3d3e1a179c94d5ef902787e4afd84219af6b2afcc0dd4255bbeb6052b501d033c4c2720f66a3c5
6
+ metadata.gz: fed562528e8e17efda88a0ee1ccb92f8a444feab8776c6d8680125281beeb92fe07373b285a490332b44329cd65bf517ab7fc20347591ed2271f69915eb5798e
7
+ data.tar.gz: 75a5813a7847d2eae1a5f1df5b3d1b3c5412ee096a02e1107b29345d0d6c0413c27017927d4c2fb4c0835d884f9d2dc2d4dba706f827757c5c93be89ffc6ccb8
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ install: bundle install
3
+ rvm:
4
+ - 2.2.1
5
+ script:
6
+ - RUBYOPT=-W0 bundle exec rake test
7
+ git:
8
+ depth: 10
9
+ notifications:
10
+ email: false
11
+ before_install:
12
+ - gem install bundler -v '= 1.10.6'
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ # PaperCup
2
+
3
+ ![TravisCI Badge](https://magnum.travis-ci.com/casapick/paper-cup.svg?token=MzqzdCmqpmmxRGFLmFqv&branch=master)
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 the response is a JSON the gem will parse it, if not it will show as it cames
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, body: {name: 'pepe'}, headers: { "Content-Type" => "application/json"})`
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.response # It will print the response returned by the endpoint
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
@@ -0,0 +1,10 @@
1
+ # Dir.glob(['./lib/tasks/*.rake']).each { |r| require r }
2
+
3
+ require 'rake/testtask'
4
+ task default: :test
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << "test"
8
+ t.test_files = FileList['test/*_test.rb', "test/paper_cup_test/**_test.rb"]
9
+ t.verbose = true
10
+ end
@@ -3,14 +3,14 @@ require_relative 'utils'
3
3
 
4
4
  module PaperCup
5
5
  class Response
6
- attr_accessor :status, :response
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 response
13
- @response ||= begin
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.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
@@ -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.response.first["framework"], "The framework must be rails"
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.response}#{r.status}", "The response must be the same"
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.response
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.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