lockme 0.1.66 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +11 -0
- data/README.md +5 -3
- data/lib/lockme/base.rb +5 -0
- data/lib/lockme/json_utils.rb +1 -1
- data/lib/lockme/request.rb +8 -8
- data/lib/lockme/reservation.rb +17 -7
- data/lib/lockme/room.rb +2 -2
- data/lib/lockme/test.rb +1 -1
- data/lib/lockme/version.rb +1 -1
- data/lib/lockme.rb +1 -0
- data/lockme.gemspec +1 -0
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa37c02a432d1e93c389daf8c240f029b1773fec
|
4
|
+
data.tar.gz: 7a77a01614ca111df43be45d3b5427b3648c81f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34b50102fa3a223bb655491e82c45c3176fc14a29620e77241d17726acd104b9127ed17d54d0d554c982818d31c59421097aac249fbc14ca667fd9164a3c7a84
|
7
|
+
data.tar.gz: e705504893e95198d349208b4428c3855a4753e6b28abceba4f3bdf487c3a0f30ea0903be41fd73daa19ace1b0abda4649249ec8aa3911f91760a1f02bcd4ebd
|
data/.travis.yml
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
sudo: false
|
2
|
+
env:
|
3
|
+
global:
|
4
|
+
- CC_TEST_REPORTER_ID=2b34c204b674fac709e16283b3b6c75b3d7b5cd88d15f4d73d5262d8df16d700
|
2
5
|
language: ruby
|
3
6
|
rvm:
|
4
7
|
- 2.3.1
|
5
8
|
before_install: gem install bundler -v 1.14.3
|
9
|
+
before_script:
|
10
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
11
|
+
- chmod +x ./cc-test-reporter
|
12
|
+
- ./cc-test-reporter before-build
|
13
|
+
script:
|
14
|
+
- bundle exec rake test
|
15
|
+
after_script:
|
16
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Lockme
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/hajder/lockme.svg?branch=master)](https://travis-ci.org/hajder/lockme)
|
4
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/d14d98a40a58ca93238a/maintainability)](https://codeclimate.com/github/hajder/lockme/maintainability)
|
5
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/d14d98a40a58ca93238a/test_coverage)](https://codeclimate.com/github/hajder/lockme/test_coverage)
|
6
|
+
[![Gem](https://img.shields.io/gem/v/lockme.svg)](https://rubygems.org/gems/lockme)
|
7
|
+
|
3
8
|
Lockme is a Ruby gem to interact with [lockme.pl](https://lockme.pl) API.
|
4
9
|
|
5
10
|
## Installation
|
@@ -33,13 +38,10 @@ If you wish to debug the requests sent set `Lockme.logger` to `$stdout` or `Rail
|
|
33
38
|
|
34
39
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
35
40
|
|
36
|
-
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).
|
37
|
-
|
38
41
|
## Contributing
|
39
42
|
|
40
43
|
Bug reports and pull requests are welcome on GitHub at https://github.com/hajder/lockme.
|
41
44
|
|
42
|
-
|
43
45
|
## License
|
44
46
|
|
45
47
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/lockme/base.rb
ADDED
data/lib/lockme/json_utils.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Lockme
|
2
2
|
module JsonUtils
|
3
3
|
def to_json
|
4
|
-
@data.to_json.force_encoding('UTF-8').each_codepoint.reduce('') {|str, c| str << (c > 127 ? '\u'+c.to_s(16).rjust(4, '0') : c.chr) }
|
4
|
+
@data.to_h.to_json.force_encoding('UTF-8').each_codepoint.reduce('') {|str, c| str << (c > 127 ? '\u'+c.to_s(16).rjust(4, '0') : c.chr) }
|
5
5
|
end
|
6
6
|
end
|
7
7
|
private_constant :JsonUtils
|
data/lib/lockme/request.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
module Lockme
|
2
|
-
module
|
2
|
+
module SignedRequest
|
3
3
|
def self.perform(method, path, data = nil)
|
4
4
|
headers = signature(method, path, data)
|
5
5
|
params = {
|
6
6
|
body: data,
|
7
7
|
headers: headers,
|
8
8
|
debug_output: Lockme.logger
|
9
|
-
}.
|
10
|
-
|
9
|
+
}.delete_if {|k,v| k.nil? || v.nil? }
|
10
|
+
|
11
|
+
resp = Request.send(method.downcase, path, params).parsed_response
|
11
12
|
if resp.is_a?(Hash) && resp['error']
|
12
13
|
raise Lockme::Error.new(resp['error'])
|
13
14
|
end
|
@@ -20,9 +21,9 @@ module Lockme
|
|
20
21
|
digest = Digest::SHA1.hexdigest([
|
21
22
|
method.upcase,
|
22
23
|
path.gsub(/^\//, ''),
|
23
|
-
data
|
24
|
+
data,
|
24
25
|
Lockme.api_secret
|
25
|
-
].join(''))
|
26
|
+
].compact.join(''))
|
26
27
|
|
27
28
|
{
|
28
29
|
'Partner-Key' => Lockme.api_key,
|
@@ -35,7 +36,7 @@ module Lockme
|
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
38
|
-
module
|
39
|
+
module Request
|
39
40
|
include ::HTTParty
|
40
41
|
|
41
42
|
HEADERS = {
|
@@ -43,7 +44,7 @@ module Lockme
|
|
43
44
|
'Accept' => 'application/json',
|
44
45
|
'Content-Type' => 'application/json'
|
45
46
|
}
|
46
|
-
API_VERSION = '1.
|
47
|
+
API_VERSION = '1.1'
|
47
48
|
|
48
49
|
base_uri "https://lockme.pl/api/v#{API_VERSION}/"
|
49
50
|
headers HEADERS
|
@@ -52,5 +53,4 @@ module Lockme
|
|
52
53
|
extend Forwardable
|
53
54
|
def_delegators 'self.class', :delete, :get, :post, :put
|
54
55
|
end
|
55
|
-
private_constant :SignedRequest
|
56
56
|
end
|
data/lib/lockme/reservation.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module Lockme
|
2
|
-
class Reservation
|
2
|
+
class Reservation < Lockme::Base
|
3
3
|
def initialize(args = {})
|
4
|
-
@data = args
|
4
|
+
@data = OpenStruct.new(args)
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.find(lockme_id)
|
8
|
-
self.new(Lockme::
|
8
|
+
self.new(Lockme::SignedRequest.perform("get", "/reservation/#{lockme_id}"))
|
9
9
|
end
|
10
10
|
|
11
11
|
def save
|
12
|
-
if
|
12
|
+
if persisted?
|
13
13
|
update
|
14
14
|
else
|
15
15
|
create
|
@@ -17,16 +17,26 @@ module Lockme
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def destroy
|
20
|
-
Lockme::
|
20
|
+
Lockme::SignedRequest.perform("delete", "/reservation/#{@data.reservationid}")
|
21
|
+
end
|
22
|
+
|
23
|
+
# Check if object is persisted with Lockme
|
24
|
+
def persisted?
|
25
|
+
!@data.reservationid.nil?
|
26
|
+
end
|
27
|
+
|
28
|
+
# Provide attribute accessors
|
29
|
+
def method_missing(method, *args)
|
30
|
+
@data.send method, *args
|
21
31
|
end
|
22
32
|
|
23
33
|
def create
|
24
|
-
Lockme::
|
34
|
+
Lockme::SignedRequest.perform("put", "/reservation", self.to_json)
|
25
35
|
end
|
26
36
|
private :create
|
27
37
|
|
28
38
|
def update
|
29
|
-
Lockme::
|
39
|
+
Lockme::SignedRequest.perform("post", "/reservation/#{@data.reservationid}", self.to_json)
|
30
40
|
end
|
31
41
|
private :update
|
32
42
|
end
|
data/lib/lockme/room.rb
CHANGED
data/lib/lockme/test.rb
CHANGED
data/lib/lockme/version.rb
CHANGED
data/lib/lockme.rb
CHANGED
data/lockme.gemspec
CHANGED
@@ -23,5 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.14"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
25
|
spec.add_development_dependency "minitest", "~> 5.0"
|
26
|
+
spec.add_development_dependency "simplecov"
|
26
27
|
spec.add_dependency "httparty", "~> 0.15.6"
|
27
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lockme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Szyndel
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.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'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: httparty
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,6 +96,7 @@ files:
|
|
82
96
|
- bin/console
|
83
97
|
- bin/setup
|
84
98
|
- lib/lockme.rb
|
99
|
+
- lib/lockme/base.rb
|
85
100
|
- lib/lockme/configuration.rb
|
86
101
|
- lib/lockme/error.rb
|
87
102
|
- lib/lockme/json_utils.rb
|