crapi 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,16 @@
1
1
  module Crapi
2
+ ## The base Error class for all {Crapi}-related issues.
3
+ ##
2
4
  class Error < ::StandardError
3
5
  end
4
6
 
7
+ ## An error relating to missing, invalid, or incompatible method arguments.
8
+ ##
5
9
  class ArgumentError < Error
6
10
  end
7
11
 
12
+ ## An error relating to a 4XX/5XX HTTP response code.
13
+ ##
8
14
  class BadHttpResponseError < Error
9
15
  end
10
16
  end
@@ -1,41 +1,120 @@
1
1
  require 'active_support/all'
2
2
 
3
3
  module Crapi
4
+ ## Proxies simple CRUD methods ({#delete} / {#get} / {#patch} / {#post} / {#put}) for a
5
+ ## {Crapi::Client Crapi::Client} or another {Crapi::Proxy Crapi::Proxy}. Like
6
+ ## {Crapi::Client Crapi::Client}, it also provides a proxy generator.
7
+ ##
8
+ ## A {Crapi::Proxy Crapi::Proxy} has its own set of default headers and has a segment that is
9
+ ## prepended to its CRUD methods' *path* before being passed to the parent
10
+ ## {Crapi::Client Crapi::Client}/{Crapi::Proxy Crapi::Proxy}. This makes the proxxy functionally
11
+ ## equivalent to a new {Crapi::Client Crapi::Client} with a new base path (the parent's base path
12
+ ## plus the proxy's segment) and more default headers, but without the need for a separate
13
+ ## connection to the target system.
14
+ ##
4
15
  class Proxy
16
+ ## A Hash containing headers to send with every request (unless overriden elsewhere). In case of
17
+ ## conflicts, headers set as default for a {Crapi::Proxy Crapi::Proxy} override those set by the
18
+ ## parent. As in a {Crapi::Client Crapi::Client}, headers set by the user via the CRUD methods'
19
+ ## *headers* still override any conflicting default header.
20
+ ##
21
+ ##
22
+ ## @see Crapi::Client#default_headers Crapi::Client#default_headers
23
+ ##
5
24
  attr_accessor :default_headers
6
25
 
26
+ ## @param add [String]
27
+ ## The new base path. This path (added to the parent's base path) will be used as the base
28
+ ## path for the {Crapi::Proxy Crapi::Proxy}'s CRUD methods.
29
+ ##
30
+ ## @param to [Crapi::Client, Crapi::Proxy]
31
+ ## The parent {Crapi::Client Crapi::Client} or {Crapi::Proxy Crapi::Proxy} that we'll be
32
+ ## delegating CRUD calls to after proprocessing of headers and paths.
33
+ ##
34
+ ## @param headers [Hash]
35
+ ## The default headers to send with every request (unless overriden elsewhere).
36
+ ##
7
37
  def initialize(add:, to:, headers: nil)
8
38
  @parent = to
9
39
  @segment = add
10
40
  @default_headers = (headers || {}).with_indifferent_access
11
41
  end
12
42
 
43
+ ## Returns a new {Crapi::Proxy Crapi::Proxy} for this proxy.
44
+ ##
45
+ ##
46
+ ## @param segment [String]
47
+ ## The segment to add to this proxy's path.
48
+ ##
49
+ ## @param headers [Hash]
50
+ ## The default headers for the new proxy.
51
+ ##
52
+ ##
53
+ ## @return [Crapi::Proxy]
54
+ ##
55
+ ## @see Crapi::Client#new_proxy Crapi::Client#new_proxy
56
+ ##
13
57
  def new_proxy(segment = '/', headers: nil)
14
58
  Proxy.new(add: segment, to: self, headers: headers)
15
59
  end
16
60
 
17
61
  ## CRUD methods ...
18
62
 
63
+ ## CRUD method: DELETE
64
+ ##
65
+ ##
66
+ ## @return [Object]
67
+ ##
68
+ ## @see Crapi::Client#delete Crapi::Client#delete
69
+ ##
19
70
  def delete(path, headers: {}, query: {})
20
71
  @parent.delete("/#{@segment}/#{path}".gsub(%r{/+}, '/'),
21
72
  headers: @default_headers.merge(headers), query: query)
22
73
  end
23
74
 
75
+ ## CRUD method: GET
76
+ ##
77
+ ##
78
+ ## @return [Object]
79
+ ##
80
+ ## @see Crapi::Client#get Crapi::Client#get
81
+ ##
24
82
  def get(path, headers: {}, query: {})
25
83
  @parent.get("/#{@segment}/#{path}".gsub(%r{/+}, '/'),
26
84
  headers: @default_headers.merge(headers), query: query)
27
85
  end
28
86
 
87
+ ## CRUD method: PATCH
88
+ ##
89
+ ##
90
+ ## @return [Object]
91
+ ##
92
+ ## @see Crapi::Client#patch Crapi::Client#patch
93
+ ##
29
94
  def patch(path, headers: {}, query: {}, payload: {})
30
95
  @parent.patch("/#{@segment}/#{path}".gsub(%r{/+}, '/'),
31
96
  heades: @default_headers.merge(headers), query: query, payload: payload)
32
97
  end
33
98
 
99
+ ## CRUD method: POST
100
+ ##
101
+ ##
102
+ ## @return [Object]
103
+ ##
104
+ ## @see Crapi::Client#post Crapi::Client#post
105
+ ##
34
106
  def post(path, headers: {}, query: {}, payload: {})
35
107
  @parent.post("/#{@segment}/#{path}".gsub(%r{/+}, '/'),
36
108
  headers: @default_headers.merge(headers), query: query, payload: payload)
37
109
  end
38
110
 
111
+ ## CRUD method: PUT
112
+ ##
113
+ ##
114
+ ## @return [Object]
115
+ ##
116
+ ## @see Crapi::Client#put Crapi::Client#put
117
+ ##
39
118
  def put(path, headers: {}, query: {}, payload: {})
40
119
  @parent.put("/#{@segment}/#{path}".gsub(%r{/+}, '/'),
41
120
  headers: @default_headers.merge(headers), query: query, payload: payload)
@@ -1,3 +1,11 @@
1
+ ## The Crapi module houses the {Crapi::Client Crapi::Client} and {Crapi::Proxy Crapi::Proxy} classes
2
+ ## in this gem.
3
+ ##
1
4
  module Crapi
2
- VERSION = '0.1.2'.freeze
5
+ ## The canonical **crapi** gem version.
6
+ ##
7
+ ## This should only ever be updated *immediately* before a release; the commit that updates this
8
+ ## value should be pushed **by** the `rake release` process.
9
+ ##
10
+ VERSION = '0.1.3'.freeze
3
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nestor Custodio
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-22 00:00:00.000000000 Z
11
+ date: 2018-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -129,6 +129,27 @@ files:
129
129
  - bin/console
130
130
  - bin/setup
131
131
  - crapi.gemspec
132
+ - docs/Crapi.html
133
+ - docs/Crapi/ArgumentError.html
134
+ - docs/Crapi/BadHttpResponseError.html
135
+ - docs/Crapi/Client.html
136
+ - docs/Crapi/Error.html
137
+ - docs/Crapi/Proxy.html
138
+ - docs/Net/HTTP.html
139
+ - docs/_index.html
140
+ - docs/class_list.html
141
+ - docs/css/common.css
142
+ - docs/css/full_list.css
143
+ - docs/css/style.css
144
+ - docs/file.README.html
145
+ - docs/file_list.html
146
+ - docs/frames.html
147
+ - docs/index.html
148
+ - docs/js/app.js
149
+ - docs/js/full_list.js
150
+ - docs/js/jquery.js
151
+ - docs/method_list.html
152
+ - docs/top-level-namespace.html
132
153
  - lib/crapi.rb
133
154
  - lib/crapi/client.rb
134
155
  - lib/crapi/errors.rb