api_pattern 0.0.1 → 0.0.3

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
  SHA256:
3
- metadata.gz: b824d5027294a5fbec1ae0b376da2e1031527c930aec4d70ba6924efbc1b3750
4
- data.tar.gz: 8ec7712914d9d528de5fea6ff78bc618d0e6245da5ef0fb71475334510d168e8
3
+ metadata.gz: 247c97a2884ca5e72a787e2d53e3dac38b72ea010146f2784039d012cf1c86a7
4
+ data.tar.gz: 1a4bef352470b85aef4fe9ab2fb74001f46a81adedfd253001c13df4f20ee814
5
5
  SHA512:
6
- metadata.gz: 06ede13830d1bd225cc84484c3a1aa5c6d7f723c6e32c010e27bc0c1cdefe09f1b892bdedd22d7e18fb507ac411afad7346a50103b6aeb607b426bd82f74e710
7
- data.tar.gz: 9a414a4e91c7413d430fe3e059b9eb7ff5ccb407197c4b2a358a379b81151c181a364f1613b46e28b2fcc83f5148a4ba98372fd30f4304dcff66544a4748f703
6
+ metadata.gz: 46e7b6e3a75e087cd6e313dfa0858034e5ad910687a7f19252aefa041943421056233d49e464a0cd0983bc5dc82bbea6cb4b5e61c1286a04fb050a763077a032
7
+ data.tar.gz: 40982eae5e02ede1efea95db5aed6acf9f5a782f06c4bb8773de3d267d1954eb151505d835effb20158b00b23c185ef9314d86d18e770ca53b70ced8e4c28d06
data/README.md CHANGED
@@ -6,7 +6,7 @@ A base set of ops for all my API clients to make maintenance easier
6
6
  Add this line to your application's Gemfile:
7
7
 
8
8
  ```ruby
9
- gem 'api-pattern'
9
+ gem 'api_pattern'
10
10
  ```
11
11
 
12
12
  And then execute:
@@ -34,12 +34,12 @@ module ApiPattern
34
34
 
35
35
  private
36
36
 
37
- def unauthorised_and_send(http_method:, path:, payload: {}, params: {}, format: :json)
37
+ def unauthorised_and_send(http_method:, path:, custom_url: nil, payload: {}, params: {}, format: :json)
38
38
  start_time = get_micro_second_time
39
39
 
40
40
  response = ::HTTParty.send(
41
41
  http_method.to_sym,
42
- construct_base_path(path, params),
42
+ construct_base_path(path, params, custom_url: custom_url),
43
43
  body: process_payload(payload),
44
44
  headers: {
45
45
  "Content-Type": @content_type,
@@ -52,7 +52,7 @@ module ApiPattern
52
52
  construct_response_object(response, path, start_time, end_time)
53
53
  end
54
54
 
55
- def authorise_and_send(http_method:, path:, payload: {}, params: {}, format: :json)
55
+ def authorise_and_send(http_method:, path:, custom_url: nil, payload: {}, params: {}, format: :json)
56
56
  start_time = get_micro_second_time
57
57
 
58
58
  send_params = {
@@ -66,7 +66,7 @@ module ApiPattern
66
66
 
67
67
  response = ::HTTParty.send(
68
68
  http_method.to_sym,
69
- construct_base_path(path, params),
69
+ construct_base_path(path, params, custom_url: custom_url),
70
70
  **configure_auth(send_params)
71
71
  )
72
72
 
@@ -116,8 +116,12 @@ module ApiPattern
116
116
  (Time.now.to_f * 1_000_000).to_i
117
117
  end
118
118
 
119
- def construct_base_path(path, params)
120
- constructed_path = "#{base_path}/#{path}"
119
+ def construct_base_path(path, params, custom_url: nil)
120
+ if custom_url
121
+ constructed_path = "#{custom_url}/#{path}"
122
+ else
123
+ constructed_path = "#{base_path}/#{path}"
124
+ end
121
125
 
122
126
  if params == {}
123
127
  constructed_path
@@ -127,6 +131,8 @@ module ApiPattern
127
131
  end
128
132
 
129
133
  def process_payload(payload)
134
+ return nil if payload.nil? || payload == {} || payload == ""
135
+
130
136
  if @content_type.to_s.downcase.include?("json")
131
137
  payload.to_json
132
138
  else
@@ -1,3 +1,3 @@
1
1
  module ApiPattern
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_pattern
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - trex22
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-24 00:00:00.000000000 Z
11
+ date: 2023-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty