remotr 0.0.1 → 0.0.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/README.md +14 -0
- data/lib/remotr/configurable.rb +25 -0
- data/lib/remotr/configuration.rb +5 -0
- data/lib/remotr/respondable.rb +66 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa3338323e20475acdafb664d9653e97ae8079f8
|
4
|
+
data.tar.gz: 8e7bb12c942214fd8286fea3398497d16980291d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39400293b478e483f564e3ca2f691b86b9b2dbaae25b369c62b40c32597432e1af4cb05f2c11b7d786df15d08febd9efc9263bdf713638342be30ce849c3a030
|
7
|
+
data.tar.gz: c97885b428f64e0cd7773ee7b1445d6c3192570a2dd7473e72a61504b1875535fdfe7076a7af0a4d88b7f253cfb605739787ed1c514ace4506cebefb80d05f7c
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'remotr/configuration'
|
2
|
+
|
3
|
+
module Remotr
|
4
|
+
module Configurable
|
5
|
+
|
6
|
+
# Public: Returns the the configuration instance.
|
7
|
+
#
|
8
|
+
def config
|
9
|
+
@config ||= ::Remotr::Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
# Public: Yields the configuration instance.
|
13
|
+
#
|
14
|
+
def configure(&block)
|
15
|
+
yield config
|
16
|
+
end
|
17
|
+
|
18
|
+
# Public: Reset the configuration (useful for testing).
|
19
|
+
#
|
20
|
+
def reset!
|
21
|
+
@config = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'operation'
|
2
|
+
require 'httparty'
|
3
|
+
require 'active_support/concern'
|
4
|
+
require 'active_support/core_ext/string'
|
5
|
+
|
6
|
+
module Remotr
|
7
|
+
module Respondable
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def config
|
12
|
+
self.name.deconstantize.constantize.config
|
13
|
+
end
|
14
|
+
|
15
|
+
def namespace
|
16
|
+
self.name.demodulize.pluralize.underscore
|
17
|
+
end
|
18
|
+
|
19
|
+
def application
|
20
|
+
self.name.deconstantize.underscore
|
21
|
+
end
|
22
|
+
|
23
|
+
def get(path = {}, params = {})
|
24
|
+
request :get, path, params
|
25
|
+
end
|
26
|
+
|
27
|
+
def post(path = {}, params = {}, body = nil)
|
28
|
+
request :post, path, params
|
29
|
+
end
|
30
|
+
|
31
|
+
def delete(path = {}, params = {})
|
32
|
+
request :delete, path, params
|
33
|
+
end
|
34
|
+
|
35
|
+
def put(path = {}, params = {}, body = nil)
|
36
|
+
request :put, path, params
|
37
|
+
end
|
38
|
+
|
39
|
+
def request(method, path, params, body = nil)
|
40
|
+
url = URI.join(config.base_uri, "#{config.base_path}#{path}").to_s
|
41
|
+
fail ArgumentError unless %w( get post delete put update ).include? method.to_s
|
42
|
+
|
43
|
+
HTTParty.send method, url,
|
44
|
+
query: params,
|
45
|
+
headers: { 'Accept' => 'application/json' },
|
46
|
+
basic_auth: { username: 'api', password: config.api_key }
|
47
|
+
end
|
48
|
+
|
49
|
+
def respond_with(httparty_response, custom_namespace = nil)
|
50
|
+
use_namespace = custom_namespace || namespace
|
51
|
+
object = httparty_response.parsed_response ? httparty_response.parsed_response[use_namespace.to_s] : nil
|
52
|
+
|
53
|
+
if httparty_response.code.to_i.between? 200, 299
|
54
|
+
Operations.success :remote_request_succeeded, object: object, code: httparty_response.code, body: httparty_response.body
|
55
|
+
else
|
56
|
+
Operations.failure :remote_request_failed, object: httparty_response, code: httparty_response.code
|
57
|
+
end
|
58
|
+
|
59
|
+
rescue JSON::ParserError
|
60
|
+
Operations.failure :remote_request_parsing_failed, object: httparty_response
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remotr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bukowskis
|
@@ -114,7 +114,11 @@ executables: []
|
|
114
114
|
extensions: []
|
115
115
|
extra_rdoc_files: []
|
116
116
|
files:
|
117
|
+
- README.md
|
117
118
|
- lib/remotr.rb
|
119
|
+
- lib/remotr/configurable.rb
|
120
|
+
- lib/remotr/configuration.rb
|
121
|
+
- lib/remotr/respondable.rb
|
118
122
|
homepage: https://github.com/bukowskis/remotr
|
119
123
|
licenses: []
|
120
124
|
metadata: {}
|