unfor_base_api 0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 473477d9da42f99f2674fea8ad4f1016991d4f32
4
+ data.tar.gz: 620f7ec2151742f95cb9836cc8b53475f0ac1e14
5
+ SHA512:
6
+ metadata.gz: da478bb4ae9a2555a0642dba51cad3ec1d66b987dd5dccab6562a265b6d961569b2ac7cf947840c95f12b068ee713491893e460ec0d4c03da6d76b6f108b2061
7
+ data.tar.gz: a80f49de956e39b80dd64516e0603f109a8ac1c9255eb1f064258c282d4e2384198922b3c139b1956c4d845acf016d294e456fadb0908a23fb69068eb3dc8190
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.1
2
+
3
+ * Initial release
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 unformatt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # UnforBaseApi
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/unfor_base_api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'unfor_base_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install unfor_base_api
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/unfor_base_api.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,98 @@
1
+ class UnforBaseApi
2
+ def initialize(args={})
3
+ @endpoint = args[:endpoint]
4
+ @access_token = args[:access_token]
5
+ end
6
+
7
+ def last_response
8
+ @last_response
9
+ end
10
+
11
+ def last_result
12
+ @last_result
13
+ end
14
+
15
+ protected
16
+
17
+ def get_request(action, params={}, headers={})
18
+ begin
19
+ response = RestClient.get("#{@endpoint_url}#{action}", {params: params}.merge(headers))
20
+ parse_response(get_response_kind(headers), response)
21
+ rescue => e
22
+ parse_response('object', e.response)
23
+ end
24
+ end
25
+
26
+ def post_request(action, params={}, headers={})
27
+ begin
28
+ response = RestClient.post("#{@endpoint_url}#{action}", params, headers)
29
+ parse_response(get_response_kind(headers), response)
30
+ rescue => e
31
+ parse_response('object', e.response)
32
+ end
33
+ end
34
+
35
+ def put_request(action, params={}, headers={})
36
+ begin
37
+ response = RestClient.put("#{@endpoint_url}#{action}", params, headers)
38
+ parse_response(get_response_kind(headers), response)
39
+ rescue => e
40
+ parse_response('object', e.response)
41
+ end
42
+ end
43
+
44
+ def patch_request(action, params={}, headers={})
45
+ begin
46
+ response = RestClient.patch("#{@endpoint_url}#{action}", params, headers)
47
+ parse_response(get_response_kind(headers), response)
48
+ rescue => e
49
+ parse_response('object', e.response)
50
+ end
51
+ end
52
+
53
+ def head_request(action, params={}, headers={})
54
+ begin
55
+ response = RestClient.head("#{@endpoint_url}#{action}", params)
56
+ parse_response(get_response_kind(headers), response)
57
+ rescue => e
58
+ parse_response('object', e.response)
59
+ end
60
+ end
61
+
62
+ def delete_request(action, params={}, headers={})
63
+ begin
64
+ response = RestClient.delete("#{@endpoint_url}#{action}", params)
65
+ parse_response(get_response_kind(headers), response)
66
+ rescue => e
67
+ parse_response('object', e.response)
68
+ end
69
+ end
70
+
71
+ def get_response_kind(headers)
72
+ api_response_kind = headers.delete('api_response_kind')
73
+ api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil?
74
+ api_response_kind.nil? ? 'object' : api_response_kind
75
+ end
76
+
77
+ def parse_response(api_response_kind, response)
78
+ @last_response = response
79
+
80
+ result = OpenStruct.new
81
+ result.status_code = response.code
82
+
83
+ if api_response_kind == 'object'
84
+ result.headers = (JSON.parse(response.headers.to_json, object_class: OpenStruct) rescue response.headers)
85
+ result.body = (JSON.parse(response.body, object_class: OpenStruct) rescue response.body)
86
+ elsif api_response_kind == 'hash'
87
+ result.headers = response.headers
88
+ result.body = (JSON.parse(response.body) rescue response.body)
89
+ else
90
+ result.headers = response.headers
91
+ result.body = response.body
92
+ end
93
+
94
+ @last_result = result
95
+
96
+ result
97
+ end
98
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unfor_base_api
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Matias Hick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.6.7
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.7
55
+ description: Base API for unformatt projects
56
+ email:
57
+ - unformatt@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - CHANGELOG.md
63
+ - LICENSE.md
64
+ - README.md
65
+ - lib/unfor_base_api.rb
66
+ homepage: https://github.com/lhconfort/unfor_base_api
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.5.2
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Base API for unformatt projects
90
+ test_files: []