wrapi 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -2
- data/README.md +4 -1
- data/Rakefile +8 -0
- data/bin/cc-test-reporter.exe +0 -0
- data/lib/wrapi/configuration.rb +7 -2
- data/lib/wrapi/connection.rb +1 -1
- data/lib/wrapi/entity.rb +29 -19
- data/lib/wrapi/request.rb +26 -18
- data/lib/wrapi/respond_to.rb +2 -2
- data/lib/wrapi/version.rb +1 -1
- data/wrapi.gemspec +2 -0
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9f4476458af28d2c64f885a156dbab8e4797d30992b8b52a92fbe9876456442
|
4
|
+
data.tar.gz: d1cd4782db7f857ca68c72f956fa2b061b029e545a81ff85901ea39958345b32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ced08d3424e62508e0dca3e85e30a7fd1a6d116b0a13bed7aec1d11b77234e8aaf93b8d4dce32c2fb3e3787baf95da59f1c595f7b7d318eb63cea9d8f301c6cf
|
7
|
+
data.tar.gz: c2984a92eef0e8038e43d3eb9bbc775490372dbc3eefe97b5ea41c475e77dc0d2b26ecaac64c93ee5977c2ccb5e3089cbdf2a479b748a18e84cb446e7d14ba32
|
data/CHANGELOG.md
CHANGED
@@ -18,3 +18,10 @@
|
|
18
18
|
## [0.2.0] - 2024-02-13
|
19
19
|
- implement option to manipulate request
|
20
20
|
|
21
|
+
## [0.4.0] - 2024-02-13
|
22
|
+
- testing/code quality
|
23
|
+
authentication tests (mocked)
|
24
|
+
test string/{}/[] entities returned with mock
|
25
|
+
request tests with mock including delete/put/post
|
26
|
+
- Entity fix issues returning json arrays
|
27
|
+
Request option to return raw response
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Wrapper API
|
2
|
+
[![Version](https://img.shields.io/gem/v/wrapi.svg)](https://rubygems.org/gems/wrapi)
|
3
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/d84930f1f1d8fae05c5c/maintainability)](https://codeclimate.com/github/jancotanis/wrapi/maintainability)
|
4
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/d84930f1f1d8fae05c5c/test_coverage)](https://codeclimate.com/github/jancotanis/wrapi/test_coverage)
|
2
5
|
|
3
|
-
Some generic
|
6
|
+
Some generic code extracted from by a number of api wrapper gems. Internal used only.
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
data/Rakefile
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'bundler/gem_tasks'
|
4
|
+
require 'dotenv'
|
4
5
|
require 'rake/testtask'
|
5
6
|
|
7
|
+
Dotenv.load
|
8
|
+
|
9
|
+
system './bin/cc-test-reporter before-build'
|
10
|
+
|
6
11
|
Rake::TestTask.new(:test) do |t|
|
7
12
|
t.libs << 'test'
|
8
13
|
t.libs << 'lib'
|
9
14
|
t.test_files = FileList['test/**/*_test.rb']
|
15
|
+
at_exit do
|
16
|
+
system './bin/cc-test-reporter after-build'
|
17
|
+
end
|
10
18
|
end
|
11
19
|
|
12
20
|
require 'rubocop/rake_task'
|
Binary file
|
data/lib/wrapi/configuration.rb
CHANGED
@@ -2,10 +2,15 @@
|
|
2
2
|
#require_relative './version'
|
3
3
|
|
4
4
|
module WrAPI
|
5
|
+
|
5
6
|
# Defines constants and methods related to configuration
|
7
|
+
# If configuration is overridden, please add following methods
|
8
|
+
# @see [self.extended(base)] to initialize the Configuration
|
9
|
+
# If additional options are added, please overide
|
10
|
+
# @see [reset] to initialize variables
|
11
|
+
# @see [options] to return the correct set of options
|
6
12
|
module Configuration
|
7
|
-
# An array of valid keys in the options hash when configuring a {
|
8
|
-
|
13
|
+
# An array of valid keys in the options hash when configuring a {WrAPI::API}
|
9
14
|
VALID_OPTIONS_KEYS = [
|
10
15
|
:access_token,
|
11
16
|
:token_type,
|
data/lib/wrapi/connection.rb
CHANGED
data/lib/wrapi/entity.rb
CHANGED
@@ -6,40 +6,37 @@ module WrAPI
|
|
6
6
|
class Entity
|
7
7
|
attr_reader :attributes
|
8
8
|
|
9
|
+
# factory method to create entity or array of entities
|
10
|
+
def self.create(attributes)
|
11
|
+
|
12
|
+
if attributes.is_a? Array
|
13
|
+
Entity.entify(attributes)
|
14
|
+
else
|
15
|
+
Entity.new(attributes) if attributes
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
9
19
|
def initialize(attributes)
|
10
20
|
@_raw = attributes
|
11
21
|
|
12
22
|
case attributes
|
13
23
|
when Hash
|
14
24
|
@attributes = attributes.clone.transform_keys(&:to_s)
|
15
|
-
when Array
|
16
|
-
# make deep copy
|
17
|
-
@attributes = entify(attributes)
|
18
25
|
else
|
19
26
|
@attributes = attributes.clone
|
20
27
|
end
|
21
28
|
end
|
22
29
|
|
23
30
|
def method_missing(method_sym, *arguments, &block)
|
24
|
-
len = arguments.length
|
25
31
|
# assignment
|
26
32
|
if (method = method_sym[/.*(?==\z)/m])
|
27
|
-
raise! ArgumentError, "wrong number of arguments (given #{
|
33
|
+
raise! ArgumentError, "wrong number of arguments (given #{arguments.length}, expected 1)", caller(1) unless arguments.length == 1
|
28
34
|
|
29
35
|
@attributes[method] = arguments[0]
|
30
36
|
elsif @attributes.include? method_sym.to_s
|
31
|
-
|
32
|
-
case r
|
33
|
-
when Hash
|
34
|
-
@attributes[method_sym.to_s] = self.class.new(r)
|
35
|
-
when Array
|
36
|
-
# make deep copy
|
37
|
-
@attributes[method_sym.to_s] = r = entify(r)
|
38
|
-
r
|
39
|
-
else
|
40
|
-
r
|
41
|
-
end
|
37
|
+
accessor(method_sym.to_s)
|
42
38
|
else
|
39
|
+
# delegate to hash
|
43
40
|
@attributes.send(method_sym, *arguments, &block)
|
44
41
|
end
|
45
42
|
end
|
@@ -55,10 +52,23 @@ module WrAPI
|
|
55
52
|
def to_json(options = {})
|
56
53
|
@_raw.to_json
|
57
54
|
end
|
58
|
-
|
59
|
-
def
|
55
|
+
|
56
|
+
def accessor(method)
|
57
|
+
case @attributes[method]
|
58
|
+
when Hash
|
59
|
+
@attributes[method] = self.class.new(@attributes[method])
|
60
|
+
when Array
|
61
|
+
# make deep copy
|
62
|
+
@attributes[method] = Entity.entify(@attributes[method])
|
63
|
+
else
|
64
|
+
@attributes[method]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.entify(a)
|
60
69
|
a.map do |item|
|
61
|
-
item.is_a?(Hash) ? self.class.new(item) : item
|
70
|
+
#item.is_a?(Hash) ? self.class.new(item) : item
|
71
|
+
Entity.create(item)
|
62
72
|
end
|
63
73
|
end
|
64
74
|
end
|
data/lib/wrapi/request.rb
CHANGED
@@ -7,12 +7,12 @@ module WrAPI
|
|
7
7
|
module Request
|
8
8
|
|
9
9
|
# Perform an HTTP GET request and return entity incase format is :json
|
10
|
-
# @return if format is :json an [Entity] is returned, otherwhise the response body
|
11
|
-
def get(path, options = {})
|
10
|
+
# @return if format is :json and !raw an [Entity] is returned, otherwhise the response body
|
11
|
+
def get(path, options = {}, raw=false)
|
12
12
|
response = request(:get, path, options) do |request|
|
13
13
|
yield(request) if block_given?
|
14
14
|
end
|
15
|
-
|
15
|
+
entity_response(response, raw)
|
16
16
|
end
|
17
17
|
|
18
18
|
# Perform an HTTP GET request for paged date sets response
|
@@ -27,19 +27,16 @@ module WrAPI
|
|
27
27
|
response = request(:get, path, options.merge(pager.page_options)) do |req|
|
28
28
|
request_labda.call(req) if request_labda
|
29
29
|
end
|
30
|
-
d = pager.class.data(response.body)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
d = Entity.new(d)
|
35
|
-
end
|
36
|
-
if block_given?
|
37
|
-
yield(d)
|
38
|
-
else
|
39
|
-
if d.is_a? Array
|
40
|
-
result += d
|
30
|
+
if d = pager.class.data(response.body)
|
31
|
+
d = Entity.create(d)
|
32
|
+
if block_given?
|
33
|
+
yield(d)
|
41
34
|
else
|
42
|
-
|
35
|
+
if d.is_a? Array
|
36
|
+
result += d
|
37
|
+
else
|
38
|
+
result << d
|
39
|
+
end
|
43
40
|
end
|
44
41
|
end
|
45
42
|
pager.next_page!(response.body)
|
@@ -49,26 +46,29 @@ module WrAPI
|
|
49
46
|
|
50
47
|
# Perform an HTTP POST request
|
51
48
|
# @return response is returned in json if format is :json
|
52
|
-
def post(path, options = {})
|
49
|
+
def post(path, options = {}, raw=true)
|
53
50
|
response = request(:post, path, options) do |request|
|
54
51
|
yield(request) if block_given?
|
55
52
|
end
|
53
|
+
entity_response(response, raw)
|
56
54
|
end
|
57
55
|
|
58
56
|
# Perform an HTTP PUT request
|
59
57
|
# @return response is returned in json if format is :json
|
60
|
-
def put(path, options = {})
|
58
|
+
def put(path, options = {}, raw=true)
|
61
59
|
response = request(:put, path, options) do |request|
|
62
60
|
yield(request) if block_given?
|
63
61
|
end
|
62
|
+
entity_response(response, raw)
|
64
63
|
end
|
65
64
|
|
66
65
|
# Perform an HTTP DELETE request
|
67
66
|
# @return response is returened
|
68
|
-
def delete(path, options = {})
|
67
|
+
def delete(path, options = {}, raw=false)
|
69
68
|
response = request(:delete, path, options) do |request|
|
70
69
|
yield(request) if block_given?
|
71
70
|
end
|
71
|
+
entity_response(response, raw)
|
72
72
|
end
|
73
73
|
|
74
74
|
private
|
@@ -93,5 +93,13 @@ module WrAPI
|
|
93
93
|
end
|
94
94
|
response
|
95
95
|
end
|
96
|
+
|
97
|
+
def entity_response(response, raw=false)
|
98
|
+
if :json.eql?(format) && !raw
|
99
|
+
Entity.create(pagination_class.data(response.body))
|
100
|
+
else
|
101
|
+
response
|
102
|
+
end
|
103
|
+
end
|
96
104
|
end
|
97
105
|
end
|
data/lib/wrapi/respond_to.rb
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
module WrAPI
|
3
3
|
module RespondTo
|
4
4
|
|
5
|
-
# Delegate to
|
5
|
+
# Delegate to Client
|
6
6
|
def self.method_missing(method, *args, &block)
|
7
7
|
return super unless client.respond_to?(method)
|
8
8
|
client.send(method, *args, &block)
|
9
9
|
end
|
10
10
|
|
11
|
-
# Delegate to
|
11
|
+
# Delegate to Client
|
12
12
|
def self.respond_to?(method, include_all = false)
|
13
13
|
client.respond_to?(method, include_all) || super
|
14
14
|
end
|
data/lib/wrapi/version.rb
CHANGED
data/wrapi.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wrapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janco Tanis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
description:
|
56
84
|
email: gems@jancology.com
|
57
85
|
executables: []
|
@@ -63,6 +91,7 @@ files:
|
|
63
91
|
- Gemfile
|
64
92
|
- README.md
|
65
93
|
- Rakefile
|
94
|
+
- bin/cc-test-reporter.exe
|
66
95
|
- lib/wrapi.rb
|
67
96
|
- lib/wrapi/api.rb
|
68
97
|
- lib/wrapi/authentication.rb
|