shilpa20 1.0.4 → 1.1.6

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
  SHA256:
3
- metadata.gz: ccf6bd9827cff339753649ad9519d86b24c8ce22d7a7f3533b476fae840d9372
4
- data.tar.gz: 28c81e9dd9351fbdf28b99f5523b0344376cdce98a1ae6ac7497b220464c2a6a
3
+ metadata.gz: 52cc89d7f8c70db39933a56a2d4881314dc60e98301691b874552ae21f2910c6
4
+ data.tar.gz: 1d079a77aaad308889c94a65335ea109d6c254a97b36740c64103f01ec1df43f
5
5
  SHA512:
6
- metadata.gz: ef17ed9e1ac0f8e4a3cdbb4168adf287f77a36378864109ec6a2377e286918f71bda963bb2c1f7d2e41e46f816ca3189048d7c6971f20153a1fe91970a638108
7
- data.tar.gz: 10c0e47aeb09f662ef999db2353b4d6d69a5b166f15b522b07e2e92a4a0651009685f66b4036aa7473992b03cff38936447a459365c1bf2451d98ff07ba781c1
6
+ metadata.gz: babc8dc984c0787cb6860bc28ccd46768fda64d81c9e0b83098f7e2df25fc3801b44a72e2e19330a482550afc81bb7042a7c790bce732db305b9f2550f88f274
7
+ data.tar.gz: 196d4d84c35829cffc8d88219ab4df1bdfe38f2f21e869a6bad6d4b47e7bc9510941897214f1ddb43cc8b1dc017c3a95e0f216ef49cddee2ba2b1300655cdd8a
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+ # gem "rails"
5
+ gem 'rspec', :require => 'spec'
6
+ gem 'rest-client'
7
+ gem 'json'
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+ # Default directory to look in is `/spec`
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+ class Authentication
3
+ attr_accessor :grant_type
4
+ attr_accessor :client_id
5
+ attr_accessor :client_secret
6
+ attr_accessor :username
7
+ attr_accessor :password
8
+
9
+ def initialize grant_type: nil, client_id: nil, client_secret: nil, username: nil, password: nil
10
+ self.grant_type, self.client_id, self.client_secret, self.username, self.password =
11
+ grant_type, client_id, client_secret, username, password
12
+ end
13
+
14
+
15
+ def to_json(*a)
16
+ {
17
+ grant_type: @grant_type,
18
+ client_id: @client_id,
19
+ client_secret: @client_secret,
20
+ username: @username,
21
+ password: @password
22
+ }.to_json(*a)
23
+ end
24
+
25
+ def self.json_create(o)
26
+ b_from_json = new
27
+ b_from_json.grant_type = o['grant_type']
28
+ b_from_json.client_id = o['client_id']
29
+ b_from_json.client_secret = o['client_secret']
30
+ b_from_json.username = o['username']
31
+ b_from_json.password = o['password']
32
+ b_from_json
33
+ end
34
+
35
+ def self.get_payload(auth_data)
36
+ return auth_data.to_json
37
+ end
38
+ end
@@ -0,0 +1,23 @@
1
+ require 'json'
2
+ class ClientInfoBase
3
+ attr_accessor :client_id
4
+ attr_accessor :client_secret
5
+ attr_accessor :user
6
+
7
+ def initialize
8
+ # @user = []
9
+ end
10
+
11
+ def to_json(*a)
12
+ {
13
+ client_id: @client_id, client_secret: @client_secret, user: @user
14
+ }.to_json(*a)
15
+ end
16
+ def self.json_create(o)
17
+ a_from_json = new
18
+ a_from_json.client_id = o['client_id']
19
+ a_from_json.client_secret = o['client_secret']
20
+ a_from_json.user = o['user']
21
+ a_from_json
22
+ end
23
+ end
@@ -0,0 +1,49 @@
1
+ require 'json'
2
+ class User
3
+ attr_accessor :first_name
4
+ attr_accessor :last_name
5
+ attr_accessor :password
6
+ attr_accessor :current_password
7
+ attr_accessor :new_password
8
+ attr_accessor :date_of_birth
9
+ attr_accessor :email
10
+ attr_accessor :image_url
11
+
12
+ def initialize first_name: nil, last_name: nil, password: nil, current_password: nil, new_password: nil,
13
+ date_of_birth:nil, email: nil, image_url: nil
14
+ self.first_name, self.last_name, self.password,self.current_password,self.new_password,
15
+ self.date_of_birth, self.email, self.image_url =
16
+ first_name, last_name, password,current_password, new_password, date_of_birth, email, image_url
17
+ end
18
+
19
+
20
+ def to_json(*a)
21
+ {
22
+ first_name: @first_name,
23
+ last_name: @last_name,
24
+ password: @password,
25
+ current_password: @current_password,
26
+ new_password: @new_password,
27
+ date_of_birth: @date_of_birth,
28
+ email: @email,
29
+ image_url: @image_url
30
+ }.to_json(*a)
31
+ end
32
+
33
+ def self.json_create(o)
34
+ b_from_json = new
35
+ b_from_json.first_name = o['first_name']
36
+ b_from_json.last_name = o['last_name']
37
+ b_from_json.password = o['password']
38
+ b_from_json.current_password = o['current_password']
39
+ b_from_json.new_password = o['new_password']
40
+ b_from_json.date_of_birth = o['date_of_birth']
41
+ b_from_json.email = o['email']
42
+ b_from_json.image_url = o['image_url']
43
+ b_from_json
44
+ end
45
+
46
+ def self.get_payload(userWithClientInfo)
47
+ return userWithClientInfo.to_json
48
+ end
49
+ end
@@ -0,0 +1,32 @@
1
+ require 'json'
2
+ class Widget
3
+ attr_accessor :name
4
+ attr_accessor :description
5
+ attr_accessor :kind
6
+
7
+ def initialize name: nil, description: nil, kind: nil
8
+ self.name, self.description, self.kind =
9
+ name, description, kind
10
+ end
11
+
12
+ def to_json(*a)
13
+ {
14
+ name: @name,
15
+ description: @description,
16
+ kind: @kind
17
+ }.to_json(*a)
18
+ end
19
+
20
+ def self.json_create(o)
21
+ b_from_json = new
22
+ b_from_json.name = o['name']
23
+ b_from_json.description = o['description']
24
+ b_from_json.kind = o['kind']
25
+ b_from_json
26
+ end
27
+
28
+ def self.get_payload(widget)
29
+ return widget.to_json
30
+ end
31
+
32
+ end
@@ -0,0 +1,15 @@
1
+ require 'json'
2
+ class WidgetBase
3
+ attr_accessor :widget
4
+
5
+ def to_json(*a)
6
+ {
7
+ widget: @widget
8
+ }.to_json(*a)
9
+ end
10
+ def self.json_create(o)
11
+ a_from_json = new
12
+ a_from_json.widget = o['widget']
13
+ a_from_json
14
+ end
15
+ end
@@ -0,0 +1,58 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require_relative '../domain/authentication.rb'
4
+
5
+ class AuthenticationService
6
+ @@authentication_url = 'https://showoff-rails-react-production.herokuapp.com/oauth/token'
7
+
8
+ def self.create_authentication(auth_data)
9
+ auth_payload = Authentication.get_payload(auth_data)
10
+ return RestClient::Request.execute(method: :post, url: @@authentication_url,
11
+ payload: auth_payload, headers: {'Content-Type': 'application/json'})
12
+ end
13
+
14
+ # to remove once tested
15
+ def self.create_auth_data
16
+ auth = Authentication.new
17
+ auth.grant_type = "password"
18
+ auth.client_id = "277ef29692f9a70d511415dc60592daf4cf2c6f6552d3e1b769924b2f2e2e6fe"
19
+ auth.client_secret = "d6106f26e8ff5b749a606a1fba557f44eb3dca8f48596847770beb9b643ea352"
20
+ auth.username = "sachinmurthy93@gmail.com"
21
+ auth.password = "password"
22
+ return auth
23
+ end
24
+
25
+ def self.refresh_token(refresh_data)
26
+ refresh_payload = Authentication.get_payload(refresh_data)
27
+ return RestClient::Request.execute(method: :post, url: @@authentication_url,
28
+ payload: refresh_payload, headers: {'Content-Type': 'application/json'})
29
+ end
30
+
31
+ def self.provide_access_token
32
+ auth_data = AuthenticationService.create_auth_data
33
+ authJson = AuthenticationService.create_authentication(auth_data)
34
+ res_data = JSON.parse(authJson)
35
+ access_token = res_data['data']['token']['access_token']
36
+ return access_token
37
+ end
38
+
39
+ end
40
+
41
+ # to remove once tested -test create auth
42
+ =begin
43
+
44
+
45
+ auth_data = AuthenticationService.create_auth_data
46
+ authJson = AuthenticationService.create_authentication(auth_data)
47
+ #res_data = JSON.parse(authJson)
48
+ #access_token = res_data['data']['token']['access_token']
49
+ #puts "Access token : " + access_token
50
+ puts authJson
51
+ =end
52
+
53
+
54
+
55
+ #js = '{"name":"SSSS", "id":"1"}'
56
+ #obj = JSON.parse(js)
57
+ #obj.delete("id")
58
+ #puts obj.to_json
@@ -0,0 +1,82 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require_relative '../domain/client_info_base.rb'
4
+ require_relative '../domain/user.rb'
5
+ require_relative 'authentication_service'
6
+
7
+ class UserService
8
+ @@create_user_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users'
9
+ @@create_update_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/me'
10
+ @@check_email_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/email'
11
+ @@reset_password_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/reset_password'
12
+ @@change_password_url ='https://showoff-rails-react-production.herokuapp.com/api/v1/users/me/password'
13
+ @@show_logged_in_user_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/me'
14
+ @@show_user_id_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/'
15
+
16
+ def self.create_user(user_with_client_info)
17
+ create_user_payload = User.get_payload(user_with_client_info)
18
+ return RestClient::Request.execute(method: :post, url: @@create_user_url,
19
+ payload: create_user_payload, headers: {'Content-Type': 'application/json'})
20
+ end
21
+
22
+ def self.update_user(user_with_client_info, bearer_token)
23
+ update_user_payload = User.get_payload(user_with_client_info)
24
+ return RestClient::Request.execute(method: :put, url: @@create_update_url,
25
+ payload: update_user_payload,
26
+ headers: {'Content-Type': 'application/json', 'Authorization':'Bearer '+ bearer_token})
27
+ end
28
+
29
+ def self.check_email(user_with_client_info)
30
+ return RestClient::Request.execute(method: :get, url: @@check_email_url,
31
+ headers: {'Content-Type': 'application/json', params: {:email => user_with_client_info.user.email , :client_id => user_with_client_info.client_id, :client_secret => user_with_client_info.client_secret}})
32
+ end
33
+
34
+ def self.reset_password(user_with_client_info)
35
+ reset_password_payload = User.get_payload(user_with_client_info)
36
+ return RestClient::Request.execute(method: :post, url: @@reset_password_url,
37
+ payload: reset_password_payload,
38
+ headers: {'Content-Type': 'application/json'})
39
+ end
40
+
41
+ def self.change_password(user_with_client_info, bearer_token)
42
+ change_password_payload = User.get_payload(user_with_client_info)
43
+ return RestClient::Request.execute(method: :post, url: @@change_password_url,
44
+ payload: change_password_payload,
45
+ headers: {'Content-Type': 'application/json', 'Authorization':'Bearer '+ bearer_token})
46
+ end
47
+
48
+ def self.show_logged_in_user(bearer_token)
49
+ return RestClient::Request.execute(method: :get, url: @@show_logged_in_user_url,
50
+ headers: {'Content-Type': 'application/json', 'Authorization':'Bearer '+ bearer_token})
51
+ end
52
+
53
+ def self.show_user_id(user_id, bearer_token)
54
+ url_with_id = @@show_user_id_url + "#{user_id}"
55
+ return RestClient::Request.execute(method: :get, url: url_with_id,
56
+ headers: {'Content-Type': 'application/json', 'Authorization':'Bearer '+ bearer_token})
57
+ end
58
+
59
+ # to remove once tested
60
+ def self.create_user_with_client_info
61
+ user = User.new
62
+ user.first_name = "Sachin New"
63
+ user.last_name = "Murthy"
64
+ user.password = "password"
65
+ user.current_password = "password"
66
+ user.new_password = "password123"
67
+ user.date_of_birth = 1464083530
68
+ user.email = "sachinmurthy101@gmail.com"
69
+ user.image_url = "https://static.thenounproject.com/png/961-200.png"
70
+
71
+ user_with_client_info = ClientInfoBase.new
72
+ user_with_client_info.client_id = "277ef29692f9a70d511415dc60592daf4cf2c6f6552d3e1b769924b2f2e2e6fe"
73
+ user_with_client_info.client_secret = "d6106f26e8ff5b749a606a1fba557f44eb3dca8f48596847770beb9b643ea352"
74
+ user_with_client_info.user = user
75
+ return user_with_client_info
76
+ end
77
+
78
+ end
79
+
80
+ # to remove once tested
81
+ #userWithClientIfno = UserService.create_user_with_client_info
82
+ #puts UserService.show_user_id(382)
@@ -0,0 +1,41 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require_relative 'authentication_service'
4
+ require_relative 'user_service'
5
+
6
+ class UserWidgetService
7
+ @@own_widgets_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/users/me/widgets'
8
+ @@widgets_by_user_id_url ='https://showoff-rails-react-production.herokuapp.com/api/v1/users/'
9
+
10
+ def self.get_private_widgets(user_with_client_info, bearer_token)
11
+ return RestClient::Request.execute(method: :get, url: @@own_widgets_url,
12
+ headers: {'Content-Type': 'application/json', params: {:client_id => user_with_client_info.client_id, :client_secret => user_with_client_info.client_secret},
13
+ 'Authorization':'Bearer '+ bearer_token})
14
+ end
15
+
16
+ def self.get_private_widgets_with_search_term(user_with_client_info, search_term, bearer_token)
17
+ return RestClient::Request.execute(method: :get, url: @@own_widgets_url,
18
+ headers: {'Content-Type': 'application/json', params: {:client_id => user_with_client_info.client_id, :client_secret => user_with_client_info.client_secret, :term => search_term},
19
+ 'Authorization':'Bearer '+ bearer_token})
20
+ end
21
+
22
+ def self.get_widgets_by_user_id(user_with_client_info, user_id, bearer_token)
23
+ url_with_id = @@widgets_by_user_id_url + "#{user_id}" + "/widgets"
24
+ return RestClient::Request.execute(method: :get, url: url_with_id,
25
+ headers: {'Content-Type': 'application/json', params: {:client_id => user_with_client_info.client_id, :client_secret => user_with_client_info.client_secret},
26
+ 'Authorization':'Bearer '+ bearer_token})
27
+ end
28
+
29
+ def self.get_widgets_by_user_id_with_search_term(user_with_client_info, user_id, search_term, bearer_token)
30
+ url_with_id = @@widgets_by_user_id_url + "#{user_id}" + "/widgets"
31
+ return RestClient::Request.execute(method: :get, url: url_with_id,
32
+ headers: {'Content-Type': 'application/json', params: {:client_id => user_with_client_info.client_id, :client_secret => user_with_client_info.client_secret, :term => search_term},
33
+ 'Authorization':'Bearer '+ bearer_token})
34
+ end
35
+
36
+ end
37
+
38
+ # to remove once tested
39
+ #widget_json = WidgetService.create_widget_data
40
+ #userWithClientIfno = UserService.create_user_with_client_info
41
+ #puts UserWidgetService.search_list_user_id(userWithClientIfno, 382, "visible")
@@ -0,0 +1,70 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require_relative '../domain/widget_base.rb'
4
+ require_relative '../domain/widget.rb'
5
+ require_relative 'authentication_service'
6
+ require_relative 'user_service'
7
+
8
+ class WidgetService
9
+ @@create_widget_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/widgets'
10
+ @@update_destroy_widget_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/widgets/'
11
+ @@list_widget_url = 'https://showoff-rails-react-production.herokuapp.com/api/v1/widgets/visible'
12
+
13
+ def self.create_widget(widget_post_data, bearer_token)
14
+ create_widget_payload = Widget.get_payload(widget_post_data)
15
+ puts "widgets create payload : " + create_widget_payload
16
+ return RestClient::Request.execute(method: :post, url: @@create_widget_url,
17
+ payload: create_widget_payload,
18
+ headers: {'Content-Type': 'application/json', 'Authorization':'Bearer '+ bearer_token})
19
+ end
20
+
21
+ def self.update_widget(widget_post_data, widget_id, bearer_token)
22
+ update_url_with_widget_id = @@update_destroy_widget_url + "#{widget_id}"
23
+ update_widget_payload = Widget.get_payload(widget_post_data)
24
+ puts "widgets update payload : " + update_widget_payload
25
+ return RestClient::Request.execute(method: :put, url: update_url_with_widget_id,
26
+ payload: update_widget_payload,
27
+ headers: {'Content-Type': 'application/json', 'Authorization':'Bearer '+ bearer_token})
28
+ end
29
+
30
+ def self.destroy_widget(widget_id, bearer_token)
31
+ destroy_url_with_widget_id = @@update_destroy_widget_url + "#{widget_id}"
32
+ return RestClient::Request.execute(method: :delete, url: destroy_url_with_widget_id,
33
+ headers: {'Content-Type': 'application/json', 'Authorization':'Bearer '+ bearer_token})
34
+ end
35
+
36
+ def self.get_private_widgets(bearer_token)
37
+ return RestClient::Request.execute(method: :get, url: @@create_widget_url,
38
+ headers: {'Content-Type': 'application/json', 'Authorization':'Bearer '+ bearer_token})
39
+ end
40
+
41
+ def self.get_public_widgets(user_with_client_info, bearer_token)
42
+ return RestClient::Request.execute(method: :get, url: @@list_widget_url,
43
+ headers: {'Content-Type': 'application/json', params: {:client_id => user_with_client_info.client_id, :client_secret => user_with_client_info.client_secret},
44
+ 'Authorization':'Bearer '+ bearer_token})
45
+ end
46
+
47
+ def self.get_public_widgets_with_search_term(user_with_client_info, search_term, bearer_token)
48
+ return RestClient::Request.execute(method: :get, url: @@list_widget_url,
49
+ headers: {'Content-Type': 'application/json', params: {:client_id => user_with_client_info.client_id, :client_secret => user_with_client_info.client_secret, :term => search_term},
50
+ 'Authorization':'Bearer '+ bearer_token})
51
+ end
52
+
53
+ # to remove once tested
54
+ def self.create_widget_data
55
+ widget = Widget.new
56
+ widget.name = "widget_2"
57
+ widget.description = "widget two - updated"
58
+ widget.kind = "visible"
59
+
60
+ widget_base = WidgetBase.new
61
+ widget_base.widget = widget
62
+ return widget_base
63
+ end
64
+
65
+ end
66
+
67
+ # to remove once tested
68
+ #widget_json = WidgetService.create_widget_data
69
+ userWithClientIfno = UserService.create_user_with_client_info
70
+ puts WidgetService.search_list_widget(userWithClientIfno, "widget one")
data/lib/shilpa20.rb CHANGED
@@ -1,7 +1,11 @@
1
1
  require 'rest-client'
2
- require './services/authentication_service'
3
- require './services/user_service'
4
- require './services/user_widget_service'
2
+ #require './authentication_service'
3
+ #require './user_service'
4
+ #require './user_widget_service'
5
+
6
+ require File.dirname(__FILE__) + '/shilpa20/authentication_service'
7
+ require File.dirname(__FILE__) + '/shilpa20/user_service'
8
+ require File.dirname(__FILE__) + '/shilpa20/user_widget_service'
5
9
 
6
10
  class Shilpa20
7
11
  @@client_id
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shilpa20
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sachin Murthy
@@ -30,7 +30,18 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
+ - Gemfile
34
+ - Rakefile
35
+ - lib/domain/authentication.rb
36
+ - lib/domain/client_info_base.rb
37
+ - lib/domain/user.rb
38
+ - lib/domain/widget.rb
39
+ - lib/domain/widget_base.rb
33
40
  - lib/shilpa20.rb
41
+ - lib/shilpa20/authentication_service.rb
42
+ - lib/shilpa20/user_service.rb
43
+ - lib/shilpa20/user_widget_service.rb
44
+ - lib/shilpa20/widget_service.rb
34
45
  homepage: http://rubygems.org/gems/shilpa20
35
46
  licenses:
36
47
  - MIT