splynx_api 0.1.0
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 +7 -0
- data/.gitignore +26 -0
- data/Gemfile +8 -0
- data/README.md +149 -0
- data/Rakefile +2 -0
- data/bin/setup +8 -0
- data/lib/splynx_api/version.rb +3 -0
- data/lib/splynx_api.rb +112 -0
- data/splynx_api.gemspec +38 -0
- metadata +121 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 5ba0b3eede2ae4ce281d97e848dc098d07dfe6c8
|
|
4
|
+
data.tar.gz: 24eecb1e9b0525e5f226e5d11d18677c1f41f9a8
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9ddf0d1157cd961f2339a61ba0540c19e47d066b5c973a3c7733e3fb073fadf2a48860e42090dc7a608ab7e1c2d3ae14a2fd8c2190c6233595730a4112b4e65a
|
|
7
|
+
data.tar.gz: c665fd970a25d2f1498f0142e4e0e370d8ef35e4c3f70c7926ac8300ff031ebf7005dd6c8aeb41d03f1a2e41bd1a84fb665698b3f046e1940c90135e37a0dd34
|
data/.gitignore
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
.DS_Store
|
|
2
|
+
*.gem
|
|
3
|
+
*.rbc
|
|
4
|
+
*.sassc
|
|
5
|
+
.bundle
|
|
6
|
+
.config
|
|
7
|
+
.yardoc
|
|
8
|
+
.rvmrc
|
|
9
|
+
.rspec
|
|
10
|
+
.sass-cache
|
|
11
|
+
.DS_Store
|
|
12
|
+
Gemfile.lock
|
|
13
|
+
InstalledFiles
|
|
14
|
+
_yardoc
|
|
15
|
+
doc/
|
|
16
|
+
coverage
|
|
17
|
+
lib/bundler/man
|
|
18
|
+
capybara-*.html
|
|
19
|
+
pkg
|
|
20
|
+
rdoc
|
|
21
|
+
spec/reports
|
|
22
|
+
spec/tmp
|
|
23
|
+
test/tmp
|
|
24
|
+
test/version_tmp
|
|
25
|
+
tmp
|
|
26
|
+
.idea/
|
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# SplynxApi
|
|
2
|
+
|
|
3
|
+
A simple helper for [Splynx API](http://docs.splynx.apiary.io/) based on [REST Client](https://github.com/rest-client/rest-client).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'splynx_api'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install splynx_api
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
Get your API data from <Your splynx url>/admin/administration/api-keys. Before use the API please check your api permissions.
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
require 'splynx_api'
|
|
26
|
+
|
|
27
|
+
api = SplynxApi::Api.new({
|
|
28
|
+
:base_url => '<protocol>://<domain>',
|
|
29
|
+
:key => 'Your Splynx Api key',
|
|
30
|
+
:secret => 'Your Splynx Api secret',
|
|
31
|
+
:verify_ssl => false
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
# Get list of all locations
|
|
35
|
+
response = api.get('/admin/administration/locations')
|
|
36
|
+
|
|
37
|
+
puts response.code
|
|
38
|
+
puts response.body
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## SplynxApi::Api reference
|
|
42
|
+
|
|
43
|
+
### new(params)
|
|
44
|
+
* :base_url - Splynx url with protocol
|
|
45
|
+
* :key - Splynx Api key
|
|
46
|
+
* :secret - Splynx Api secret
|
|
47
|
+
* :verify_ssl - Enable verify ssl (Default: true)
|
|
48
|
+
|
|
49
|
+
Create new instance of Api
|
|
50
|
+
|
|
51
|
+
### get(uri, id)
|
|
52
|
+
* uri - Required
|
|
53
|
+
* id - Optional
|
|
54
|
+
|
|
55
|
+
Get list of models. Optionally, an id may be provided to retrieve one a model.
|
|
56
|
+
|
|
57
|
+
Returned RestClient::Response or error object.
|
|
58
|
+
|
|
59
|
+
### post(uri, params)
|
|
60
|
+
* uri - Required
|
|
61
|
+
* params - Required
|
|
62
|
+
|
|
63
|
+
Create new model with provided attributes value.
|
|
64
|
+
Returned RestClient::Response or error object.
|
|
65
|
+
|
|
66
|
+
Example:
|
|
67
|
+
```ruby
|
|
68
|
+
# Create new location named "My Location"
|
|
69
|
+
response = api.post('/admin/administration/locations', {
|
|
70
|
+
'name' => 'My Location'
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### put(uri, id, params)
|
|
75
|
+
* uri - Required
|
|
76
|
+
* id - Required
|
|
77
|
+
* params - Required
|
|
78
|
+
|
|
79
|
+
Update existing model.
|
|
80
|
+
|
|
81
|
+
Returned RestClient::Response or error object.
|
|
82
|
+
|
|
83
|
+
Example:
|
|
84
|
+
```ruby
|
|
85
|
+
# Rename location with id 1 to "Updated Location"
|
|
86
|
+
response = api.put('/admin/administration/locations', 1, {
|
|
87
|
+
'name' => 'My Location'
|
|
88
|
+
})
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### search(uri, params)
|
|
92
|
+
* uri - Required
|
|
93
|
+
* params - Required
|
|
94
|
+
|
|
95
|
+
Search model by custom parameters.
|
|
96
|
+
|
|
97
|
+
Returned RestClient::Response or error object.
|
|
98
|
+
|
|
99
|
+
Example:
|
|
100
|
+
```ruby
|
|
101
|
+
# Search location with name "Updated Location"
|
|
102
|
+
response = api.search('/admin/administration/locations', {
|
|
103
|
+
'main_attributes' => {
|
|
104
|
+
'name' => 'Updated Location'
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### delete(uri, id)
|
|
110
|
+
* uri - Required
|
|
111
|
+
* id - Required
|
|
112
|
+
|
|
113
|
+
Delete model by id.
|
|
114
|
+
|
|
115
|
+
Returned RestClient::Response or error object.
|
|
116
|
+
|
|
117
|
+
Example:
|
|
118
|
+
```ruby
|
|
119
|
+
# Delete location with id 1
|
|
120
|
+
response = api.delete('/admin/administration/locations', 1)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### How to get administrator information
|
|
124
|
+
Set session hash property for get administrator information in next request.
|
|
125
|
+
|
|
126
|
+
Example:
|
|
127
|
+
```ruby
|
|
128
|
+
api.sash = 'Your session hash'
|
|
129
|
+
api.get('/admin/customers/customer')
|
|
130
|
+
|
|
131
|
+
puts api.administrator
|
|
132
|
+
|
|
133
|
+
# Returned:
|
|
134
|
+
#{
|
|
135
|
+
# :id => 'Admin ID',
|
|
136
|
+
# :role => 'Admin role',
|
|
137
|
+
# :partner => 'Admin partner ID'
|
|
138
|
+
#}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Development
|
|
142
|
+
|
|
143
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
|
144
|
+
|
|
145
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
146
|
+
|
|
147
|
+
## Contributing
|
|
148
|
+
|
|
149
|
+
Bug reports and pull requests are welcome on Bitbucket at https://bitbucket.org/splynx/splynx-ruby-api.
|
data/Rakefile
ADDED
data/bin/setup
ADDED
data/lib/splynx_api.rb
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
require 'splynx_api/version'
|
|
2
|
+
require 'openssl'
|
|
3
|
+
require 'cgi'
|
|
4
|
+
require 'rest-client'
|
|
5
|
+
require 'php_http_build_query'
|
|
6
|
+
|
|
7
|
+
module SplynxApi
|
|
8
|
+
class Api
|
|
9
|
+
attr_accessor :sash
|
|
10
|
+
|
|
11
|
+
def initialize(params)
|
|
12
|
+
@base_url = params[:base_url]
|
|
13
|
+
@key = params[:key]
|
|
14
|
+
@secret = params[:secret]
|
|
15
|
+
@verify_ssl = params[:verify_ssl].nil? ? true : params[:verify_ssl]
|
|
16
|
+
@version = '1.0'
|
|
17
|
+
@nonce_v = Time.now.to_i
|
|
18
|
+
@sash = nil
|
|
19
|
+
@administrator = nil
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def administrator
|
|
23
|
+
@administrator
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def signature
|
|
27
|
+
str = "#{@nonce_v}#{@key}"
|
|
28
|
+
digest = OpenSSL::Digest::SHA256.new
|
|
29
|
+
OpenSSL::HMAC.hexdigest(digest, @secret, str).upcase
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def auth
|
|
33
|
+
auth = {
|
|
34
|
+
:nonce => @nonce_v,
|
|
35
|
+
:key => @key,
|
|
36
|
+
:signature => signature
|
|
37
|
+
}
|
|
38
|
+
unless @sash.nil?
|
|
39
|
+
auth[:sash] = @sash
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
@nonce_v = @nonce_v + 1
|
|
43
|
+
|
|
44
|
+
PHP.http_build_query(auth)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def url(uri, id = nil, params = nil)
|
|
48
|
+
result = "#{@base_url}/api/#{@version}#{uri}"
|
|
49
|
+
|
|
50
|
+
unless id.nil?
|
|
51
|
+
result = "#{result}/#{id}"
|
|
52
|
+
end
|
|
53
|
+
unless params.nil?
|
|
54
|
+
params_string = PHP.http_build_query(params)
|
|
55
|
+
result = "#{result}?#{params_string}"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
result
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def process_response(response)
|
|
62
|
+
headers = response.headers
|
|
63
|
+
unless headers[:spl_administrator_id].nil?
|
|
64
|
+
@administrator = {
|
|
65
|
+
:id => headers[:spl_administrator_id],
|
|
66
|
+
:role => headers[:spl_administrator_role],
|
|
67
|
+
:partner => headers[:spl_administrator_partner]
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
response
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def perform(method, url, params = nil)
|
|
74
|
+
begin
|
|
75
|
+
response = RestClient::Request.execute(
|
|
76
|
+
method: method,
|
|
77
|
+
url: url,
|
|
78
|
+
verify_ssl: @verify_ssl,
|
|
79
|
+
payload: params,
|
|
80
|
+
headers: {
|
|
81
|
+
:Authorization => "Splynx-EA (#{auth})",
|
|
82
|
+
:user_agent => "Splynx Ruby API #{@version}"
|
|
83
|
+
})
|
|
84
|
+
process_response(response)
|
|
85
|
+
rescue StandardError => e
|
|
86
|
+
e
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def get(uri, id = nil)
|
|
91
|
+
perform(:get, url(uri, id))
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def post(uri, params)
|
|
95
|
+
perform(:post, url(uri), params)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def delete(uri, id)
|
|
99
|
+
perform(:delete, url(uri, id))
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def put(uri, id, params)
|
|
103
|
+
perform(:put, url(uri, id), params)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def search(uri, params)
|
|
107
|
+
perform(:get, url(uri, nil, params))
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
protected :signature, :auth, :url, :perform, :process_response
|
|
111
|
+
end
|
|
112
|
+
end
|
data/splynx_api.gemspec
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'splynx_api/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'splynx_api'
|
|
8
|
+
spec.version = SplynxApi::VERSION
|
|
9
|
+
spec.authors = ['Tsumanchuk Volodymyr']
|
|
10
|
+
spec.email = ['buorn2011@gmail.com']
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Splynx API}
|
|
13
|
+
spec.description = %q{Module for Splynx API}
|
|
14
|
+
spec.homepage = 'https://bitbucket.org/splynx/splynx-ruby-api'
|
|
15
|
+
|
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
18
|
+
# if spec.respond_to?(:metadata)
|
|
19
|
+
# spec.metadata['allowed_push_host'] = ''
|
|
20
|
+
# else
|
|
21
|
+
# raise 'RubyGems 2.0 or newer is required to protect against ' \
|
|
22
|
+
# 'public gem pushes.'
|
|
23
|
+
# end
|
|
24
|
+
|
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
|
27
|
+
end
|
|
28
|
+
spec.bindir = 'exe'
|
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
30
|
+
spec.require_paths = ['lib']
|
|
31
|
+
|
|
32
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
|
33
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
34
|
+
|
|
35
|
+
spec.add_dependency 'rest-client', '~> 2.0.2'
|
|
36
|
+
spec.add_dependency 'openssl', '~> 2.0.5'
|
|
37
|
+
spec.add_dependency 'php_http_build_query', '~> 0.1'
|
|
38
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: splynx_api
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Tsumanchuk Volodymyr
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-10-23 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.15'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.15'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.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: 2.0.2
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 2.0.2
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: openssl
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 2.0.5
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 2.0.5
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: php_http_build_query
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0.1'
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0.1'
|
|
83
|
+
description: Module for Splynx API
|
|
84
|
+
email:
|
|
85
|
+
- buorn2011@gmail.com
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- ".gitignore"
|
|
91
|
+
- Gemfile
|
|
92
|
+
- README.md
|
|
93
|
+
- Rakefile
|
|
94
|
+
- bin/setup
|
|
95
|
+
- lib/splynx_api.rb
|
|
96
|
+
- lib/splynx_api/version.rb
|
|
97
|
+
- splynx_api.gemspec
|
|
98
|
+
homepage: https://bitbucket.org/splynx/splynx-ruby-api
|
|
99
|
+
licenses: []
|
|
100
|
+
metadata: {}
|
|
101
|
+
post_install_message:
|
|
102
|
+
rdoc_options: []
|
|
103
|
+
require_paths:
|
|
104
|
+
- lib
|
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
|
+
requirements:
|
|
112
|
+
- - ">="
|
|
113
|
+
- !ruby/object:Gem::Version
|
|
114
|
+
version: '0'
|
|
115
|
+
requirements: []
|
|
116
|
+
rubyforge_project:
|
|
117
|
+
rubygems_version: 2.6.13
|
|
118
|
+
signing_key:
|
|
119
|
+
specification_version: 4
|
|
120
|
+
summary: Splynx API
|
|
121
|
+
test_files: []
|