plyom_user 0.0.9 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21afb0468207382be2ac9260201924a50b9038d9
4
- data.tar.gz: fc52cfd0f2c4945a63c8fdf8e7e568531146f6b9
3
+ metadata.gz: bbeb291a67f4ae621111e0ec0590d8051046e889
4
+ data.tar.gz: c9b6fb65948d09da4af443982ac1a1216c30df6c
5
5
  SHA512:
6
- metadata.gz: a4313d5f1b8cc39f439474de8c71b331f7c725a1b94dba2ee017d4e9cf9cea8576753a8b72c800225166a145ff7d83307a210d10088efa3839db515ad6284eaf
7
- data.tar.gz: f56ac33148c3f0379f520f713c8988e4b1b20ef25fe20bf7c69a6558fec65c793d4c3455fc00c8ad510e5d029a5ae49ffbe232114cea63fed4c2f882d66f1268
6
+ metadata.gz: 08e43b87973877e1f8111cbb698aa6a2ddeacaa3e56f09337d6868b42676bc3ce74b7e96875d806799077a8e6cfaf451bdaf98c974187499772887891e5a92ac
7
+ data.tar.gz: ef1d6bd9376f391bfbaf358e081c353930f6e035a5c301da7266e619dfdb135cb55dd39cc54ae4515fc22b72286a2bdfab46c7b5ef594c5cecb0404df6c7f5e4
data/lib/plyom_user.rb CHANGED
@@ -1,80 +1,71 @@
1
1
  require "plyom_user/version"
2
- require "active_support"
3
- require 'active_support/core_ext/class'
4
2
  require "httparty"
5
3
  require "json"
6
4
 
7
- module PlyomUser
5
+ class PlyomUser
6
+ class_attribute :id, :name, :email, :username, :password, :password_confirmation, :password_digest, :status, :token, :created_at, :updated_at
8
7
 
9
- def self.included(base)
10
- base.extend ClassMethods
8
+ def initialize(params={})
9
+ params.each { |var, val| public_send("#{var}=", val) }
11
10
  end
12
11
 
13
- module ClassMethods
14
- attr_accessor :id, :name, :email, :username, :password, :password_confirmation, :password_digest, :status, :token, :created_at, :updated_at
12
+ def self.all
13
+ list = []
14
+ response = action_by("read")
15
+ objs = JSON.parse(response.body)
16
+ objs.each { |obj| list << self.new(obj) }
17
+ list
18
+ end
15
19
 
16
- def initialize(params={})
17
- params.each { |var, val| public_send("#{var}=", val) }
18
- end
20
+ def self.find(id)
21
+ response = action_by("read", id: id)
22
+ obj = JSON.parse(response.body)
23
+ self.new(obj)
24
+ end
19
25
 
20
- def self.all
21
- list = []
22
- response = action_by("read")
23
- objs = JSON.parse(response.body)
24
- objs.each { |obj| list << self.new(obj) }
25
- list
26
+ def save
27
+ param_names = ["name", "email", "username", "password", "password_confirmation", "status"]
28
+ data = filter_params(param_names)
29
+ if data.length > 0
30
+ paramters = { user: data }
31
+ paramters.update({ id: @id }) if @id.to_i > 0
32
+ action = @id.to_i > 0 ? "update" : "add"
33
+ response = PlyomUser.action_by(action, paramters)
26
34
  end
35
+ end
27
36
 
28
- def self.find(id)
29
- response = action_by("read", id: id)
30
- obj = JSON.parse(response.body)
31
- self.new(obj)
32
- end
37
+ def remove
38
+ PlyomUser.action_by("del", id: @id)
39
+ end
33
40
 
34
- def save
35
- param_names = ["name", "email", "username", "password", "password_confirmation", "status"]
36
- data = filter_params(param_names)
37
- if data.length > 0
38
- paramters = { user: data }
39
- paramters.update({ id: @id }) if @id.to_i > 0
40
- action = @id.to_i > 0 ? "update" : "add"
41
- response = UserPlyom.action_by(action, paramters)
41
+ private
42
+ def filter_params(names=[])
43
+ params = {}
44
+ self.instance_variables.each do |var|
45
+ var_name = var.to_s.delete "@"
46
+ var_value = self.instance_variable_get var
47
+ params.update({var_name => var_value}) if names.include?(var_name)
42
48
  end
49
+ params
43
50
  end
44
51
 
45
- def remove
46
- UserPlyom.action_by("del", id: @id)
52
+ def self.action_by(action, params={})
53
+ case action
54
+ when "read"
55
+ HTTParty.get("#{uri}/#{params[:id]}")
56
+ when "add"
57
+ HTTParty.post("#{uri}", query: params)
58
+ when "del"
59
+ HTTParty.delete("#{uri}/#{params[:id]}")
60
+ when "update"
61
+ HTTParty.patch("#{uri}/#{params[:id]}", query: params) if params.size > 1
62
+ HTTParty.put("#{uri}/#{params[:id]}", query: params) if params.size == 1
63
+ end
47
64
  end
48
65
 
49
- private
50
- def filter_params(names=[])
51
- params = {}
52
- self.instance_variables.each do |var|
53
- var_name = var.to_s.delete "@"
54
- var_value = self.instance_variable_get var
55
- params.update({var_name => var_value}) if names.include?(var_name)
56
- end
57
- params
58
- end
59
-
60
- def self.action_by(action, params={})
61
- case action
62
- when "read"
63
- HTTParty.get("#{uri}/#{params[:id]}")
64
- when "add"
65
- HTTParty.post("#{uri}", query: params)
66
- when "del"
67
- HTTParty.delete("#{uri}/#{params[:id]}")
68
- when "update"
69
- HTTParty.patch("#{uri}/#{params[:id]}", query: params) if params.size > 1
70
- HTTParty.put("#{uri}/#{params[:id]}", query: params) if params.size == 1
71
- end
72
- end
73
-
74
- def self.uri
75
- host = ENV["plyom_user_host"]
76
- path = "/api/users"
77
- host + path
78
- end
79
- end
80
- end
66
+ def self.uri
67
+ host = "http://localhost:3000"
68
+ path = "/api/users"
69
+ host + path
70
+ end
71
+ end
@@ -1,3 +1,3 @@
1
1
  module PlyomUser
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
data/plyom_user.gemspec CHANGED
@@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "activesupport"
22
21
  spec.add_dependency "httparty", "~> 0.11.0"
23
22
  spec.add_development_dependency "bundler", "~> 1.3"
24
23
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plyom_user
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Pileggi
@@ -10,20 +10,6 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: httparty
29
15
  requirement: !ruby/object:Gem::Requirement