emmy-http 0.1.10 → 0.1.11

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: 05594b33af30c50c3901325534fb2fbd5fb011b1
4
- data.tar.gz: 3569e0ba991cd322c232c939a8a574a344836bc3
3
+ metadata.gz: 8dfa617e0358d6ec58af123a7d50763b62dcdff5
4
+ data.tar.gz: 8e7a0ce2e5985c4ab369a9457769c6c299065340
5
5
  SHA512:
6
- metadata.gz: 49a503bfb5485e215e05ca6fb5e136b9285efd681c22841a7cb7cd0a82d37d8312779d09ac573c197a25af1646650a8818c58a17ef7197459b518b3076177c06
7
- data.tar.gz: c57e79bc762c45e9e9845c3b77bea6a0a5f764336570f4831263d5b88962d9939b3fd6aceb4426dfc645f70ff974930c08b41ba9cfedd6c89e6566d5b1d7c00d
6
+ metadata.gz: e9a8d1b8fe86fcf0eba9895d960a7518c9f5e47fed3dc0963e54e15535fb45703cc9e1d06e743020a51ded69eb21975972de04e7ece82604b6db9cf3141ea174
7
+ data.tar.gz: c0b0013eb58b9e6375e69f962faaf299e7cb2b3129118681e93414ddcc88e3708d92e44cdbe5ca70275cf3659197174f621226e5c7091e44af8c5ce95651a32b
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency "fibre", "~> 0.9.3"
24
24
  spec.add_dependency "util_pack", "~> 0.1"
25
25
  spec.add_dependency "model_pack", "~> 0.9.6"
26
+ spec.add_dependency "addressable", ">= 2.3.8"
26
27
 
27
28
  spec.add_development_dependency "bundler", "~> 1.6"
28
29
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,4 +1,5 @@
1
- require "uri"
1
+ require "addressable/uri"
2
+ require 'addressable/template'
2
3
  require "model_pack"
3
4
  require "emmy_http/version"
4
5
  require "forwardable"
@@ -9,6 +10,8 @@ module EmmyHttp
9
10
  class RequestError < HttpError; end
10
11
  class ConnectionError < HttpError; end
11
12
  class TimeoutError < HttpError; end
13
+ class EncoderError < HttpError; end
14
+ class DecoderError < HttpError; end
12
15
 
13
16
  HTTP_METHODS = %w(get head delete put post patch options)
14
17
 
@@ -5,14 +5,15 @@ module EmmyHttp
5
5
 
6
6
  #def_delegator :operation, :sync, :init, :head, :success, :error, :init!, :head!, :success!, :error!, :to_a
7
7
 
8
- attribute :type, default: "GET" # word *method* reserved in ruby
8
+ attribute :type, default: "GET" # word *method* reserved in ruby objects
9
9
  attribute :url,
10
- writer: ->(url) { url.is_a?(URI) ? url : URI.parse(url) },
11
- serialize: ->(value) { value.to_s }
10
+ writer: ->(v) { v.is_a?(String) ? Addressable::Template.new(v) : v },
11
+ serialize: ->(v) { v.is_a?(Addressable::Template) ? v.pattern : v.to_s }
12
12
  dictionary :headers
13
13
 
14
- attribute :path # replace url.path
15
- attribute :query # replace url.query
14
+ attribute :path # replace url.path
15
+ attribute :query # replace url.query
16
+ dictionary :params # params for url template
16
17
 
17
18
  # POST, PUT
18
19
  attribute :body # string, json hash
@@ -20,9 +21,11 @@ module EmmyHttp
20
21
  attribute :json # serializable hash/object to json
21
22
  attribute :file # path
22
23
 
23
- attribute :keep_alive, predicate: true
24
- attribute :redirects, default: 6
25
- attribute :raise_error, predicate: true, default: true
24
+ attribute :keep_alive, predicate: true # keep connection alive
25
+ attribute :encoding, default: true, predicate: true # encode request
26
+ attribute :decoding, default: true, predicate: true # decode response
27
+ attribute :redirects, default: 6 # max redirects to follow
28
+ attribute :raise_error, predicate: true, default: true # raise error or return nil
26
29
 
27
30
  object :timeouts, class_name: Timeouts, default: Timeouts
28
31
  object :ssl, class_name: SSL
@@ -42,6 +45,14 @@ module EmmyHttp
42
45
  operation.sync
43
46
  end
44
47
 
48
+ def real_url
49
+ if url.is_a?(Addressable::Template)
50
+ url.expand(params)
51
+ else
52
+ Addressable::URI.parse(url.to_s)
53
+ end
54
+ end
55
+
45
56
  EmmyHttp::HTTP_METHODS.each do |name|
46
57
  self.def name do |a={}|
47
58
  update_attributes(a.is_a?(String) ? {url: a} : a)
@@ -49,10 +60,6 @@ module EmmyHttp
49
60
  end
50
61
  end
51
62
 
52
- def ssl?
53
- ssl || url.scheme == 'https' || url.port == 443
54
- end
55
-
56
63
  private
57
64
 
58
65
  def error(message)
@@ -68,6 +68,10 @@ module EmmyHttp
68
68
  end
69
69
  end
70
70
 
71
+ def body?
72
+ !body.empty?
73
+ end
74
+
71
75
  def redirection?
72
76
  300 <= status && 400 > status
73
77
  end
@@ -1,3 +1,3 @@
1
1
  module EmmyHttp
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end
@@ -2,13 +2,4 @@ require "spec_helper"
2
2
  using EventObject
3
3
 
4
4
  describe EmmyHttp::Request do
5
- it "ssl flag" do
6
- req1 = EmmyHttp::Request.new(url: 'http://httpbin.org')
7
- req2 = EmmyHttp::Request.new(url: 'https://httpbin.org')
8
- req3 = EmmyHttp::Request.new(url: 'http://httpbin.org:443')
9
-
10
- expect(req1.ssl?).to eq false
11
- expect(req2.ssl?).to eq true
12
- expect(req3.ssl?).to eq true
13
- end
14
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emmy-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - inre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-21 00:00:00.000000000 Z
11
+ date: 2015-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: event_object
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.9.6
83
+ - !ruby/object:Gem::Dependency
84
+ name: addressable
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 2.3.8
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 2.3.8
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement