flespi-ruby 1.0.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/.rspec +6 -0
- data/.rubocop.yml +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +12 -0
- data/flespi-ruby.gemspec +33 -0
- data/lib/flespi.rb +111 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f262a2944da429c699df621f31663c46c4f4884de4b123ac87d09400456d46d6
|
4
|
+
data.tar.gz: fdece8e234c2c9c3dab2a26ae7ff48a96dcb4b98e48fe44b4a0ebb589121d700
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6c44d46a2a85ff6fec12c1d7871af7dd154d9a9db9b0b7bdf4ebca158ead1780f48d5695ac04e2c972d9957e3887e40a1c8573711c6d5ee785545cfce1fcb3c7
|
7
|
+
data.tar.gz: 9206da585dc048e7b858e4e7481d9be8e34fe75462c8db526cdea15a7f07b37698cf22ec09eb87108916f3d5d3d95872a08909de3918bb1591aa31a90c82a7ce
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
NewCops: enable
|
4
|
+
SuggestExtensions: false
|
5
|
+
|
6
|
+
|
7
|
+
Style/StringLiterals:
|
8
|
+
Enabled: true
|
9
|
+
EnforcedStyle: double_quotes
|
10
|
+
|
11
|
+
Style/StringLiteralsInInterpolation:
|
12
|
+
Enabled: true
|
13
|
+
EnforcedStyle: double_quotes
|
14
|
+
|
15
|
+
Style/Documentation:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Layout/LineLength:
|
22
|
+
Max: 120
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2023 Vladislav Kostikov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Flespi
|
2
|
+
[](https://badge.fury.io/rb/flespi-ruby)
|
3
|
+
|
4
|
+
[Official documentation Flespi](https://flespi.io/docs/)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
`gem "flespi-ruby"`
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
`bundle install`
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
require "flespi"
|
20
|
+
|
21
|
+
# Initialize flespi instance
|
22
|
+
flespi_client = Flespi.new("FlespiToken", debug: true)
|
23
|
+
|
24
|
+
# Get collection of all devices
|
25
|
+
flespi_client.get("/gw/devices/all")
|
26
|
+
|
27
|
+
# Get device by device id
|
28
|
+
flespi_client.get("/gw/devices/123456")
|
29
|
+
|
30
|
+
# Create new device
|
31
|
+
flespi_client.create("/gw/devices", ["configuration": { "ident": "123456" },
|
32
|
+
"device_type_id": 10,
|
33
|
+
"name": "Device name"])
|
34
|
+
|
35
|
+
# Delete device by device id
|
36
|
+
flespi_client.delete("/gw/devices/123456")
|
37
|
+
```
|
data/Rakefile
ADDED
data/flespi-ruby.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/flespi"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "flespi-ruby"
|
7
|
+
spec.version = "1.0.0"
|
8
|
+
spec.authors = ["Vladislav Kostikov"]
|
9
|
+
spec.email = ["vlad@kostikov.ru"]
|
10
|
+
|
11
|
+
spec.summary = "flespi.io"
|
12
|
+
spec.homepage = "https://github.com/vladkostikov/flespi-ruby"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
18
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(File.expand_path(f) == __FILE__) ||
|
25
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_dependency "json", ">= 1"
|
33
|
+
end
|
data/lib/flespi.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "net/http"
|
5
|
+
require "uri"
|
6
|
+
|
7
|
+
class Flespi
|
8
|
+
attr_accessor :flespi_token, :debug
|
9
|
+
|
10
|
+
VERSION = "1.0.2.1"
|
11
|
+
|
12
|
+
def initialize(flespi_token, debug: false)
|
13
|
+
self.flespi_token = flespi_token
|
14
|
+
self.debug = debug
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(url)
|
18
|
+
uri = URI.parse("https://flespi.io#{url}")
|
19
|
+
|
20
|
+
if debug
|
21
|
+
puts "================ FLESPI REQUEST ================"
|
22
|
+
puts "Request: GET https://flespi.io#{url}"
|
23
|
+
puts "================================================"
|
24
|
+
end
|
25
|
+
|
26
|
+
request = Net::HTTP::Get.new(uri)
|
27
|
+
|
28
|
+
validate_response(make_request(request, uri))
|
29
|
+
end
|
30
|
+
|
31
|
+
def create(url, parameters)
|
32
|
+
uri = URI.parse("https://flespi.io#{url}")
|
33
|
+
|
34
|
+
if debug
|
35
|
+
puts "================ FLESPI REQUEST ================"
|
36
|
+
puts "Request: POST https://flespi.io#{url}"
|
37
|
+
puts "================================================"
|
38
|
+
end
|
39
|
+
|
40
|
+
request = Net::HTTP::Post.new(uri)
|
41
|
+
|
42
|
+
validate_response(make_request(request, uri, parameters))
|
43
|
+
end
|
44
|
+
|
45
|
+
def update(url, parameters)
|
46
|
+
uri = URI.parse("https://flespi.io#{url}")
|
47
|
+
|
48
|
+
if debug
|
49
|
+
puts "================ FLESPI REQUEST ================"
|
50
|
+
puts "Request: PUT https://flespi.io#{url}"
|
51
|
+
puts "================================================"
|
52
|
+
end
|
53
|
+
|
54
|
+
request = Net::HTTP::Put.new(uri)
|
55
|
+
|
56
|
+
validate_response(make_request(request, uri, parameters))
|
57
|
+
end
|
58
|
+
|
59
|
+
def delete(url)
|
60
|
+
uri = URI.parse("https://flespi.io#{url}")
|
61
|
+
|
62
|
+
if debug
|
63
|
+
puts "================ FLESPI REQUEST ================"
|
64
|
+
puts "Request: DELETE https://flespi.io#{url}"
|
65
|
+
puts "================================================"
|
66
|
+
end
|
67
|
+
|
68
|
+
request = Net::HTTP::Delete.new(uri)
|
69
|
+
|
70
|
+
validate_response(make_request(request, uri))
|
71
|
+
end
|
72
|
+
|
73
|
+
protected
|
74
|
+
|
75
|
+
def make_request(request, uri, parameters = nil)
|
76
|
+
request["Accept"] = "application/json"
|
77
|
+
request["Authorization"] = "FlespiToken #{flespi_token}"
|
78
|
+
|
79
|
+
unless parameters.nil?
|
80
|
+
if debug
|
81
|
+
puts "================ FLESPI PARAMS ================"
|
82
|
+
puts "Parameters: #{parameters.inspect}"
|
83
|
+
puts "==============================================="
|
84
|
+
end
|
85
|
+
request.body = JSON.dump(parameters)
|
86
|
+
end
|
87
|
+
|
88
|
+
req_options = {
|
89
|
+
use_ssl: uri.scheme == "https"
|
90
|
+
}
|
91
|
+
|
92
|
+
Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
93
|
+
http.request(request)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def validate_response(response)
|
98
|
+
case response.code.to_i
|
99
|
+
when 200
|
100
|
+
{ error: false, message: JSON.parse(response.body) }
|
101
|
+
when 400
|
102
|
+
{ error: true, message: "Invalid parameters", reason: JSON.parse(response.body) }
|
103
|
+
when 401
|
104
|
+
{ error: true, message: "Invalid or missing flespi token" }
|
105
|
+
when 403
|
106
|
+
{ error: true, message: "Flespi token blocked" }
|
107
|
+
else
|
108
|
+
{ error: true, message: "Flespi internal server error" }
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flespi-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vladislav Kostikov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-11-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- vlad@kostikov.ru
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".rspec"
|
35
|
+
- ".rubocop.yml"
|
36
|
+
- LICENSE.txt
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- flespi-ruby.gemspec
|
40
|
+
- lib/flespi.rb
|
41
|
+
homepage: https://github.com/vladkostikov/flespi-ruby
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata:
|
45
|
+
homepage_uri: https://github.com/vladkostikov/flespi-ruby
|
46
|
+
source_code_uri: https://github.com/vladkostikov/flespi-ruby
|
47
|
+
rubygems_mfa_required: 'true'
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 2.6.0
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubygems_version: 3.4.21
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: flespi.io
|
67
|
+
test_files: []
|