colppy 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +36 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +38 -0
- data/Rakefile +39 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/colppy.gemspec +30 -0
- data/lib/colppy.rb +22 -0
- data/lib/colppy/client.rb +69 -0
- data/lib/colppy/core/gateway.rb +75 -0
- data/lib/colppy/core/services.rb +72 -0
- data/lib/colppy/core/support/hash.rb +49 -0
- data/lib/colppy/digest.rb +16 -0
- data/lib/colppy/errors.rb +7 -0
- data/lib/colppy/resource.rb +83 -0
- data/lib/colppy/resources/company.rb +123 -0
- data/lib/colppy/resources/customer.rb +169 -0
- data/lib/colppy/resources/product.rb +152 -0
- data/lib/colppy/resources/sell_invoice.rb +343 -0
- data/lib/colppy/resources/user.rb +97 -0
- data/lib/colppy/version.rb +3 -0
- metadata +174 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
module Colppy
|
2
|
+
module UserActions
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def session_key
|
6
|
+
@user.key
|
7
|
+
end
|
8
|
+
|
9
|
+
def username
|
10
|
+
@user.username
|
11
|
+
end
|
12
|
+
|
13
|
+
def user=(new_user)
|
14
|
+
@user = new_user
|
15
|
+
end
|
16
|
+
|
17
|
+
def sign_in(user = nil)
|
18
|
+
user ||= @user
|
19
|
+
ensure_user_valid!(user)
|
20
|
+
|
21
|
+
user.sign_in(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
def sign_out(user = nil)
|
25
|
+
user ||= @user
|
26
|
+
ensure_user_valid!(user)
|
27
|
+
|
28
|
+
user.sign_out(self)
|
29
|
+
end
|
30
|
+
|
31
|
+
def session_params
|
32
|
+
{
|
33
|
+
sesion: {
|
34
|
+
usuario: username,
|
35
|
+
claveSesion: session_key
|
36
|
+
}
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def ensure_user_valid!(user)
|
43
|
+
unless user.is_a?(Colppy::User)
|
44
|
+
raise ClientError.new("The user should be a Colppy::User instance")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class User < Resource
|
50
|
+
include Digest
|
51
|
+
attr_reader :username, :key
|
52
|
+
|
53
|
+
def initialize(username, password, key = nil)
|
54
|
+
@username = username
|
55
|
+
@password = md5(password)
|
56
|
+
@key = key
|
57
|
+
end
|
58
|
+
|
59
|
+
def sign_in(client)
|
60
|
+
response = client.call(
|
61
|
+
:user,
|
62
|
+
:sign_in,
|
63
|
+
{
|
64
|
+
usuario: @username,
|
65
|
+
password: @password
|
66
|
+
}
|
67
|
+
)
|
68
|
+
save_session(response[:data]) if response[:success]
|
69
|
+
end
|
70
|
+
|
71
|
+
def sign_out(client)
|
72
|
+
response = client.call(
|
73
|
+
:user,
|
74
|
+
:sign_out,
|
75
|
+
sesion: {
|
76
|
+
usuario: @username,
|
77
|
+
claveSesion: key
|
78
|
+
}
|
79
|
+
)
|
80
|
+
destroy_session if response[:success]
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def attr_inspect
|
86
|
+
[:username, :key]
|
87
|
+
end
|
88
|
+
|
89
|
+
def save_session(sign_in_data)
|
90
|
+
@key = sign_in_data[:claveSesion]
|
91
|
+
end
|
92
|
+
|
93
|
+
def destroy_session
|
94
|
+
@key = nil
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: colppy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Agustin Cavilliotti
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0.10'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.8'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.10'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: multi_json
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.3'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.3'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: pry
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: httplog
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: bundler
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '1.12'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '1.12'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rake
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '10.0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '10.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: minitest
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '5.0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '5.0'
|
117
|
+
description: Allow to interact with the services available on the Colppy API (https://colppy.atlassian.net/wiki/display/CA/Bienvenidos+-+Colppy+API)
|
118
|
+
email:
|
119
|
+
- cavi21@gmail.com
|
120
|
+
executables: []
|
121
|
+
extensions: []
|
122
|
+
extra_rdoc_files: []
|
123
|
+
files:
|
124
|
+
- ".gitignore"
|
125
|
+
- ".rubocop.yml"
|
126
|
+
- ".ruby-version"
|
127
|
+
- ".travis.yml"
|
128
|
+
- CODE_OF_CONDUCT.md
|
129
|
+
- Gemfile
|
130
|
+
- LICENSE.txt
|
131
|
+
- README.md
|
132
|
+
- Rakefile
|
133
|
+
- bin/console
|
134
|
+
- bin/setup
|
135
|
+
- colppy.gemspec
|
136
|
+
- lib/colppy.rb
|
137
|
+
- lib/colppy/client.rb
|
138
|
+
- lib/colppy/core/gateway.rb
|
139
|
+
- lib/colppy/core/services.rb
|
140
|
+
- lib/colppy/core/support/hash.rb
|
141
|
+
- lib/colppy/digest.rb
|
142
|
+
- lib/colppy/errors.rb
|
143
|
+
- lib/colppy/resource.rb
|
144
|
+
- lib/colppy/resources/company.rb
|
145
|
+
- lib/colppy/resources/customer.rb
|
146
|
+
- lib/colppy/resources/product.rb
|
147
|
+
- lib/colppy/resources/sell_invoice.rb
|
148
|
+
- lib/colppy/resources/user.rb
|
149
|
+
- lib/colppy/version.rb
|
150
|
+
homepage: https://github.com/goodpeople/colppy
|
151
|
+
licenses:
|
152
|
+
- MIT
|
153
|
+
metadata: {}
|
154
|
+
post_install_message:
|
155
|
+
rdoc_options: []
|
156
|
+
require_paths:
|
157
|
+
- lib
|
158
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
requirements: []
|
169
|
+
rubyforge_project:
|
170
|
+
rubygems_version: 2.4.5.1
|
171
|
+
signing_key:
|
172
|
+
specification_version: 4
|
173
|
+
summary: Client to interact with Colppy API
|
174
|
+
test_files: []
|