passety 0.0.4
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 +18 -0
- data/.travis.yml +20 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +41 -0
- data/LICENSE +20 -0
- data/README.md +17 -0
- data/Rakefile +1 -0
- data/lib/passety/collection.rb +15 -0
- data/lib/passety/collections/thing.rb +13 -0
- data/lib/passety/item.rb +33 -0
- data/lib/passety/nested_item.rb +34 -0
- data/lib/passety/property.rb +11 -0
- data/lib/passety/thing.rb +11 -0
- data/lib/passety/version.rb +3 -0
- data/lib/passety/wrapper.rb +51 -0
- data/lib/passety.rb +18 -0
- data/passety.gemspec +28 -0
- data/spec/item_spec.rb +12 -0
- data/spec/property_spec.rb +11 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/wrapper_spec.rb +30 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0dfd2e58773ce5f48434cfbdfe8f725f8c3e3028
|
4
|
+
data.tar.gz: 4619464bfe111c9664fab7e00b3429335d140ab2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd1bea6c3f9fc5a06dcb708d23c6074600cf916fce02838f74cece89872ed67a9e4e547f265491c518228d412c91d58514468727c52ce953cb92a23743299eb9
|
7
|
+
data.tar.gz: 381e87a1479ff3763aff99118b745c1eacdb9a1a670f2c42d3a2a9dab247744afbd2078b87b4cd6c394b67e50c8ec931051b60ea717ff68c82607f5b1ad9aa17
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
rvm:
|
4
|
+
- 2.0.0
|
5
|
+
|
6
|
+
gemfile:
|
7
|
+
- Gemfile
|
8
|
+
|
9
|
+
cache: bundler
|
10
|
+
|
11
|
+
addons:
|
12
|
+
code_climate:
|
13
|
+
repo_token: f51ff3b1b87654f6f32ca81f70b2f7dd0f9651da35a549a7cadd4753673e9dc8
|
14
|
+
|
15
|
+
notifications:
|
16
|
+
email:
|
17
|
+
- dev@passety.com
|
18
|
+
|
19
|
+
script:
|
20
|
+
- bundle exec rspec --color --profile
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
passety (0.0.4)
|
5
|
+
faraday
|
6
|
+
json
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.3.5)
|
12
|
+
crack (0.4.1)
|
13
|
+
safe_yaml (~> 0.9.0)
|
14
|
+
diff-lcs (1.2.5)
|
15
|
+
faraday (0.8.8)
|
16
|
+
multipart-post (~> 1.2.0)
|
17
|
+
json (1.8.1)
|
18
|
+
multipart-post (1.2.0)
|
19
|
+
rake (10.1.1)
|
20
|
+
rspec (2.14.1)
|
21
|
+
rspec-core (~> 2.14.0)
|
22
|
+
rspec-expectations (~> 2.14.0)
|
23
|
+
rspec-mocks (~> 2.14.0)
|
24
|
+
rspec-core (2.14.7)
|
25
|
+
rspec-expectations (2.14.4)
|
26
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
27
|
+
rspec-mocks (2.14.4)
|
28
|
+
safe_yaml (0.9.7)
|
29
|
+
webmock (1.16.1)
|
30
|
+
addressable (>= 2.2.7)
|
31
|
+
crack (>= 0.3.2)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
bundler (~> 1.3)
|
38
|
+
passety!
|
39
|
+
rake
|
40
|
+
rspec
|
41
|
+
webmock
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Passety
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Passety Ruby bindings
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
You don't need this source code unless you want to modify the gem. If
|
6
|
+
you just want to use the Passety Ruby bindings, you should run:
|
7
|
+
|
8
|
+
gem install passety
|
9
|
+
|
10
|
+
If you want to build the gem from source:
|
11
|
+
|
12
|
+
gem build passety.gemspec
|
13
|
+
|
14
|
+
## Requirements
|
15
|
+
|
16
|
+
* Ruby 1.9.3 or above.
|
17
|
+
* faraday, json.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Passety
|
2
|
+
module Collections
|
3
|
+
class Thing < NestedItem
|
4
|
+
def initialize(wrapper)
|
5
|
+
super(wrapper, 'collections', 'things')
|
6
|
+
end
|
7
|
+
|
8
|
+
def remove(cid, params = {})
|
9
|
+
@wrapper.perform_request { |c| c.delete(url(cid), params) }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/passety/item.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Passety
|
2
|
+
class Item
|
3
|
+
def initialize(wrapper, uri = '')
|
4
|
+
@wrapper = wrapper
|
5
|
+
@uri = uri
|
6
|
+
end
|
7
|
+
|
8
|
+
def all(params = {})
|
9
|
+
@wrapper.perform_request { |c| c.get(@uri, params) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def find(id, params = {})
|
13
|
+
@wrapper.perform_request { |c| c.get(url(id), params) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def update(id, params)
|
17
|
+
@wrapper.perform_request { |c| c.put(url(id), params) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def create(params)
|
21
|
+
@wrapper.perform_request { |c| c.post(@uri, params) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def destroy(id)
|
25
|
+
@wrapper.perform_request { |c| c.delete(url(id)) }
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def url(id)
|
30
|
+
'/' + [ @uri, id ].join('/')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Passety
|
2
|
+
class NestedItem
|
3
|
+
def initialize(wrapper, parent, uri)
|
4
|
+
@wrapper = wrapper
|
5
|
+
@parent = parent
|
6
|
+
@uri = uri
|
7
|
+
end
|
8
|
+
|
9
|
+
def all(pid, params = {})
|
10
|
+
@wrapper.perform_request { |c| c.get(url(pid), params) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def find(pid, id, params = {})
|
14
|
+
@wrapper.perform_request { |c| c.get(url(pid, id), params) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def update(pid, id, params)
|
18
|
+
@wrapper.perform_request { |c| c.put(url(pid, id), params) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def create(pid, params)
|
22
|
+
@wrapper.perform_request { |c| c.post(url(pid), params) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy(pid, id)
|
26
|
+
@wrapper.perform_request { |c| c.delete(url(pid, id)) }
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def url(pid, id = '')
|
31
|
+
'/' + [ @parent, pid, @uri, id ].join('/')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Passety
|
2
|
+
class Wrapper
|
3
|
+
def initialize(app_id, secret)
|
4
|
+
@token = authenticate(app_id, secret)
|
5
|
+
end
|
6
|
+
|
7
|
+
def authorized?
|
8
|
+
!!@token
|
9
|
+
end
|
10
|
+
|
11
|
+
def collections
|
12
|
+
@collections ||= Collection.new(self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def things
|
16
|
+
@things ||= Thing.new(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def search(name)
|
20
|
+
perform_request { |c| c.get('/explore', q: name) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def info
|
24
|
+
perform_request { |c| c.get('/') }
|
25
|
+
end
|
26
|
+
|
27
|
+
def perform_request(need_auth = true)
|
28
|
+
raise 'Not Authorized' if need_auth and not authorized?
|
29
|
+
response = yield(connection)
|
30
|
+
parse_body(response)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def parse_body(response)
|
35
|
+
body = response.env[:body].strip
|
36
|
+
JSON[body]
|
37
|
+
rescue
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def connection
|
42
|
+
@connection ||= Faraday.new(url: API_URL, headers: { 'Accept' => 'application/json; version=1', 'Authorization' => "Token #{@token}" })
|
43
|
+
end
|
44
|
+
|
45
|
+
def authenticate(app_id, secret)
|
46
|
+
response = Faraday.new(url: OAUTH_URL).post('/oauth/token', application_id: app_id, secret: secret)
|
47
|
+
auth = parse_body(response)
|
48
|
+
auth['token'] unless auth.nil?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/passety.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
require 'passety/version'
|
5
|
+
require 'passety/wrapper'
|
6
|
+
|
7
|
+
require 'passety/item'
|
8
|
+
require 'passety/nested_item'
|
9
|
+
require 'passety/collections/thing'
|
10
|
+
|
11
|
+
require 'passety/collection'
|
12
|
+
require 'passety/property'
|
13
|
+
require 'passety/thing'
|
14
|
+
|
15
|
+
module Passety
|
16
|
+
OAUTH_URL = ENV['PASSETY_OAUTH_URL'] || 'http://passety.com'
|
17
|
+
API_URL = ENV['PASSETY_API_URL'] || 'http://api.passety.com/'
|
18
|
+
end
|
data/passety.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'passety/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'passety'
|
8
|
+
spec.version = Passety::VERSION
|
9
|
+
spec.authors = ['Passety Team']
|
10
|
+
spec.email = ['support@passety.com']
|
11
|
+
spec.summary = %q{Ruby bindings for the Passety API}
|
12
|
+
spec.description = %q{Passety is the easiest way to manage things you own. See https://passety.com for details.}
|
13
|
+
spec.homepage = 'https://github.com/passety/passety-ruby'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'webmock'
|
25
|
+
|
26
|
+
spec.add_dependency 'faraday'
|
27
|
+
spec.add_dependency 'json'
|
28
|
+
end
|
data/spec/item_spec.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Passety::Item do
|
4
|
+
let(:wrapper) { double('wrapper') }
|
5
|
+
let(:uri) { double('uri') }
|
6
|
+
|
7
|
+
subject { Passety::Item.new(wrapper, uri) }
|
8
|
+
|
9
|
+
[ :all, :find, :update, :create, :destroy ].each do |action|
|
10
|
+
it { should respond_to(action) }
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Passety::Wrapper do
|
4
|
+
let(:app_id) { 'app_id' }
|
5
|
+
let(:secret) { 'secret' }
|
6
|
+
let(:token) { 'w32vd234231rr' }
|
7
|
+
let(:response) { "{\"token\": \"#{token}\"}" }
|
8
|
+
|
9
|
+
let(:wrapper) { Passety::Wrapper.new(app_id, secret) }
|
10
|
+
let(:tid) { 'AABAJ' }
|
11
|
+
|
12
|
+
before do
|
13
|
+
stub_request(:post, "#{Passety::OAUTH_URL}/oauth/token").
|
14
|
+
to_return(:status => 200, :body => response, :headers => {})
|
15
|
+
stub_request(:post, "#{Passety::API_URL}/things/")
|
16
|
+
stub_request(:post, "#{Passety::API_URL}/things/#{tid}")
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'authenticates user after initializing' do
|
20
|
+
wrapper.should be_authorized
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'initializes things object' do
|
24
|
+
wrapper.things.should_not be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'initializes properties object' do
|
28
|
+
wrapper.things.properties.should_not be_nil
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: passety
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Passety Team
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-27 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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
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: faraday
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: json
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Passety is the easiest way to manage things you own. See https://passety.com
|
98
|
+
for details.
|
99
|
+
email:
|
100
|
+
- support@passety.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- .travis.yml
|
107
|
+
- Gemfile
|
108
|
+
- Gemfile.lock
|
109
|
+
- LICENSE
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- lib/passety.rb
|
113
|
+
- lib/passety/collection.rb
|
114
|
+
- lib/passety/collections/thing.rb
|
115
|
+
- lib/passety/item.rb
|
116
|
+
- lib/passety/nested_item.rb
|
117
|
+
- lib/passety/property.rb
|
118
|
+
- lib/passety/thing.rb
|
119
|
+
- lib/passety/version.rb
|
120
|
+
- lib/passety/wrapper.rb
|
121
|
+
- passety.gemspec
|
122
|
+
- spec/item_spec.rb
|
123
|
+
- spec/property_spec.rb
|
124
|
+
- spec/spec_helper.rb
|
125
|
+
- spec/wrapper_spec.rb
|
126
|
+
homepage: https://github.com/passety/passety-ruby
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.1.11
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: Ruby bindings for the Passety API
|
150
|
+
test_files:
|
151
|
+
- spec/item_spec.rb
|
152
|
+
- spec/property_spec.rb
|
153
|
+
- spec/spec_helper.rb
|
154
|
+
- spec/wrapper_spec.rb
|