emmy-http 0.1.6 → 0.1.7
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/lib/emmy_http/model.rb +11 -76
- data/lib/emmy_http/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d2479bde7d0c2af0c66e2d9c66a8ad79bff6533
|
4
|
+
data.tar.gz: 891e9521c52bfa46ce8744ccd61d7b97e068107f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31f5a82f936ac43cd833b8f2ddcc8972d7581eeea3473fdc99ab4a51ea8356980e7b0f0e1e1a1fc07a45f05a59437fa39bcacccca614b50026eaeb8e18abdb52
|
7
|
+
data.tar.gz: 72f6b4e00517e3a50fa56d0756afe1f8566d3267a844c0132a1973a3499c9243cb8d0abf6995b4c97ba14ee7e76ed6721eeb6eac7ec684db5f4aeb826c076d98
|
data/lib/emmy_http/model.rb
CHANGED
@@ -1,72 +1,3 @@
|
|
1
|
-
#
|
2
|
-
# class Google
|
3
|
-
# include EmmyHttp::Model
|
4
|
-
# adapter EmmyExtends::EmHttpRequest
|
5
|
-
# defaults {
|
6
|
-
# headers: {
|
7
|
-
# 'Content-Type' => 'application/json'
|
8
|
-
# }
|
9
|
-
# }
|
10
|
-
#
|
11
|
-
# post ''
|
12
|
-
# end
|
13
|
-
#
|
14
|
-
# google = Google.new(url: 'http://google.com')
|
15
|
-
# response = google.sync
|
16
|
-
|
17
|
-
#
|
18
|
-
# module DigitalOcean
|
19
|
-
# using EventObject
|
20
|
-
# API_TOKEN = "b7d03a6947b217efb6f3ec3bd3504582"
|
21
|
-
#
|
22
|
-
# class DigitalOcean::Error < StandardError; end
|
23
|
-
#
|
24
|
-
# class Request
|
25
|
-
# include EmmyHttp::Model
|
26
|
-
# adapter EmmyHttp::Client::Adapter
|
27
|
-
# header 'Content-Type' => 'application/json'
|
28
|
-
# header "Authorization: Bearer #{API_TOKEN}"
|
29
|
-
#
|
30
|
-
# events :success, :error
|
31
|
-
#
|
32
|
-
# def sync
|
33
|
-
# connect
|
34
|
-
#
|
35
|
-
# Fiber.sync do |f|
|
36
|
-
# on :success do |content|
|
37
|
-
# f.resume content
|
38
|
-
# end
|
39
|
-
#
|
40
|
-
# on :error do |message|
|
41
|
-
# raise DigitalOcean::Error, message
|
42
|
-
# end
|
43
|
-
# end
|
44
|
-
# end
|
45
|
-
#
|
46
|
-
# def request
|
47
|
-
# op = super(
|
48
|
-
#
|
49
|
-
# ).op
|
50
|
-
#
|
51
|
-
# op.on :success do |response, operation, conn|
|
52
|
-
# success!(response.content)
|
53
|
-
# end
|
54
|
-
#
|
55
|
-
# op.on :error do |message, operation, conn|
|
56
|
-
# error!(message)
|
57
|
-
# end
|
58
|
-
# end
|
59
|
-
# end
|
60
|
-
#
|
61
|
-
#
|
62
|
-
# class Droplets < Request
|
63
|
-
# get list: '/v2/droplets'
|
64
|
-
# post new: '/v2/droplets'
|
65
|
-
# get get: '/v2/:id'
|
66
|
-
#
|
67
|
-
#
|
68
|
-
# end
|
69
|
-
# end
|
70
1
|
require 'singleton'
|
71
2
|
|
72
3
|
module EmmyHttp
|
@@ -87,27 +18,31 @@ module EmmyHttp
|
|
87
18
|
|
88
19
|
module ClassMethods
|
89
20
|
def request(a=nil)
|
90
|
-
instance.request.tap { |req| req.update_attributes(a) if a }
|
21
|
+
instance.request.copy.tap { |req| req.update_attributes(a) if a }
|
22
|
+
end
|
23
|
+
|
24
|
+
def request!(a=nil)
|
25
|
+
request(a).operation
|
91
26
|
end
|
92
27
|
|
93
28
|
def adapter(name)
|
94
|
-
request.adapter = name
|
29
|
+
instance.request.adapter = name
|
95
30
|
end
|
96
31
|
|
97
32
|
def url(uri)
|
98
|
-
request.url = uri
|
33
|
+
instance.request.url = uri
|
99
34
|
end
|
100
35
|
|
101
36
|
def defaults(attributes)
|
102
|
-
request.update_attributes(attributes)
|
37
|
+
instance.request.update_attributes(attributes)
|
103
38
|
end
|
104
39
|
|
105
40
|
def headers(head)
|
106
|
-
request.headers.merge!(head)
|
41
|
+
instance.request.headers.merge!(head)
|
107
42
|
end
|
108
43
|
|
109
44
|
def raise_error(flag)
|
110
|
-
request.raise_error = flag
|
45
|
+
instance.request.raise_error = flag
|
111
46
|
end
|
112
47
|
|
113
48
|
alias header headers
|
@@ -115,7 +50,7 @@ module EmmyHttp
|
|
115
50
|
EmmyHttp::HTTP_METHODS.each do |name|
|
116
51
|
define_method name do |path, as: nil|
|
117
52
|
cdef as.to_s do |*a|
|
118
|
-
instance.var(as.to_s, request
|
53
|
+
instance.var(as.to_s, request(path: path))
|
119
54
|
end
|
120
55
|
|
121
56
|
cdef "#{as}!" do |*a, &b|
|
data/lib/emmy_http/version.rb
CHANGED