sinatra_client 0.0.1 → 0.0.2
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 +4 -4
- data/.byebug_history +16 -0
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +1 -7
- data/lib/sinatra_client.rb +22 -17
- data/lib/sinatra_client/version.rb +1 -1
- data/sinatra_client-0.0.1.gem +0 -0
- data/sinatra_client.gemspec +0 -2
- metadata +4 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34cf7b797e39965e332c89a585c9c773964fa3a8df4e8fd293dab2f9354d8da7
|
4
|
+
data.tar.gz: 21c6b5ea4209493bffdd3d6f0215bb3c18663e32f0fff3e29fd51f901f5e0408
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97cdd11e82b2d4ef595f0f7c93c856d8d7a8ebfe18bd583ef26ebeae1ddd76f77df9bd1ce22a36c6767ce90045572bbfb2b76ed3ae2884c2270f395de7236547
|
7
|
+
data.tar.gz: 75ce8e3f7c470e9458bf0867f79d7e34b2bfdad693cb05693474baf3999914a066efc950fbd3309217db6f72211dc5501e331feaea7b3a752d8c59d3f800f190
|
data/.byebug_history
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
c
|
2
|
+
parse RestClient.delete('http://sinatra:9292/api/v1/postable/1/posts?postable_type=User', auth_header)
|
3
|
+
RestClient.delete('http://sinatra:9292/api/v1/postable/1/posts?postable_type=User', auth_header)
|
4
|
+
url
|
5
|
+
c
|
6
|
+
url.path
|
7
|
+
url
|
8
|
+
c
|
9
|
+
auth_header
|
10
|
+
@auth
|
11
|
+
url
|
12
|
+
c
|
13
|
+
URI.encode_www_form({a: 1, b: 2})
|
14
|
+
{}.public_methods
|
15
|
+
{}.publick_methods
|
16
|
+
c
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sinatra_client (0.0.
|
5
|
-
activerecord
|
4
|
+
sinatra_client (0.0.2)
|
6
5
|
rest-client
|
7
6
|
webmock
|
8
7
|
|
@@ -22,11 +21,6 @@ GEM
|
|
22
21
|
erubi (~> 1.4)
|
23
22
|
rails-dom-testing (~> 2.0)
|
24
23
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
25
|
-
activemodel (6.1.4)
|
26
|
-
activesupport (= 6.1.4)
|
27
|
-
activerecord (6.1.4)
|
28
|
-
activemodel (= 6.1.4)
|
29
|
-
activesupport (= 6.1.4)
|
30
24
|
activesupport (6.1.4)
|
31
25
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
32
26
|
i18n (>= 1.6, < 2)
|
data/lib/sinatra_client.rb
CHANGED
@@ -1,71 +1,76 @@
|
|
1
1
|
require "sinatra_client/version"
|
2
2
|
require "rest-client"
|
3
3
|
require "dotenv/load"
|
4
|
-
require
|
4
|
+
require 'uri'
|
5
5
|
|
6
6
|
class SinatraClient
|
7
|
-
attr_accessor :
|
7
|
+
attr_accessor :current_user_id, :url, :auth
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
@
|
9
|
+
def initialize(current_user_id = nil)
|
10
|
+
@current_user_id = current_user_id
|
11
11
|
@url = URI::HTTP.build(host: ENV['SINATRA_HOST'], port: ENV['SINATRA_PORT'], path: '/api/v1')
|
12
|
+
@auth = 'Basic ' + Base64.encode64( 'API_NAME:API_PASSWORD' ).chomp
|
12
13
|
end
|
13
14
|
|
14
15
|
def get_user_posts(user_id)
|
15
16
|
url.path << "/users/#{user_id}/posts"
|
16
|
-
parse RestClient.get(url.to_s)
|
17
|
+
parse RestClient.get(url.to_s, auth_header)
|
17
18
|
end
|
18
19
|
|
19
20
|
def create_post(post)
|
20
21
|
url.path << '/posts'
|
21
|
-
parse RestClient.post(url.to_s, post)
|
22
|
+
parse RestClient.post(url.to_s, post, auth_header)
|
22
23
|
end
|
23
24
|
|
24
25
|
def delete_post(post_id)
|
25
26
|
url.path << "/posts/#{post_id}"
|
26
|
-
url.query = { current_user:
|
27
|
-
parse RestClient.delete(url.to_s)
|
27
|
+
url.query = URI.encode_www_form({ current_user: current_user_id })
|
28
|
+
parse RestClient.delete(url.to_s, auth_header)
|
28
29
|
end
|
29
30
|
|
30
31
|
def delete_posts_for(postable_id, postable_type)
|
31
32
|
url.path << "/postable/#{postable_id}/posts"
|
32
|
-
url.query = { postable_type: postable_type }
|
33
|
-
parse RestClient.delete(url.to_s)
|
33
|
+
url.query = URI.encode_www_form({ postable_type: postable_type })
|
34
|
+
parse RestClient.delete(url.to_s, auth_header)
|
34
35
|
end
|
35
36
|
|
36
37
|
def get_group_posts(group_id)
|
37
38
|
url.path << "/groups/#{group_id}/posts"
|
38
|
-
parse RestClient.get(url.to_s)
|
39
|
+
parse RestClient.get(url.to_s, auth_header)
|
39
40
|
end
|
40
41
|
|
41
42
|
def get_user_posts_comment(post_id)
|
42
43
|
url.path << "/posts/#{post_id}/comments"
|
43
|
-
parse RestClient.get(url.to_s)
|
44
|
+
parse RestClient.get(url.to_s, auth_header)
|
44
45
|
end
|
45
46
|
|
46
47
|
def create_comment_for_post(post_id, comment)
|
47
48
|
url.path << "/posts/#{post_id}/comments"
|
48
|
-
parse RestClient.post(url.to_s, comment)
|
49
|
+
parse RestClient.post(url.to_s, comment, auth_header)
|
49
50
|
end
|
50
51
|
|
51
52
|
def delete_comment(post_id, comment_guid)
|
52
53
|
url.path << "/posts/#{post_id}/comments/#{comment_guid}"
|
53
|
-
url.query = { current_user:
|
54
|
-
parse RestClient.delete(url.to_s)
|
54
|
+
url.query = URI.encode_www_form({ current_user: current_user_id })
|
55
|
+
parse RestClient.delete(url.to_s, auth_header)
|
55
56
|
end
|
56
57
|
|
57
58
|
def create_or_delete_like(post_id, liker_id)
|
58
59
|
url.path << "/posts/#{post_id}/toggle_like"
|
59
|
-
parse RestClient.post(url.to_s, liker_id)
|
60
|
+
parse RestClient.post(url.to_s, liker_id, auth_header)
|
60
61
|
end
|
61
62
|
|
62
63
|
def get_likers(post_id)
|
63
64
|
url.path << "/posts/#{post_id}/likers"
|
64
|
-
parse RestClient.get(url.to_s)
|
65
|
+
parse RestClient.get(url.to_s, auth_header)
|
65
66
|
end
|
66
67
|
|
67
68
|
private
|
68
69
|
|
70
|
+
def auth_header
|
71
|
+
{ Authorization: auth }
|
72
|
+
end
|
73
|
+
|
69
74
|
def parse(response)
|
70
75
|
JSON.parse(response.body)
|
71
76
|
end
|
Binary file
|
data/sinatra_client.gemspec
CHANGED
@@ -13,8 +13,6 @@ Gem::Specification.new do |spec|
|
|
13
13
|
|
14
14
|
spec.add_dependency 'rest-client'
|
15
15
|
spec.add_dependency 'webmock'
|
16
|
-
spec.add_dependency 'activerecord'
|
17
|
-
spec.add_development_dependency 'byebug'
|
18
16
|
|
19
17
|
# Specify which files should be added to the gem when it is released.
|
20
18
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kozak
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -38,34 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: activerecord
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
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: byebug
|
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
41
|
description: Client for Sinatra API applications
|
70
42
|
email:
|
71
43
|
- kozakdocs@gmail.com
|
@@ -74,6 +46,7 @@ extensions: []
|
|
74
46
|
extra_rdoc_files: []
|
75
47
|
files:
|
76
48
|
- ".DS_Store"
|
49
|
+
- ".byebug_history"
|
77
50
|
- ".gitignore"
|
78
51
|
- ".rspec"
|
79
52
|
- ".travis.yml"
|
@@ -86,6 +59,7 @@ files:
|
|
86
59
|
- bin/setup
|
87
60
|
- lib/sinatra_client.rb
|
88
61
|
- lib/sinatra_client/version.rb
|
62
|
+
- sinatra_client-0.0.1.gem
|
89
63
|
- sinatra_client.gemspec
|
90
64
|
homepage:
|
91
65
|
licenses:
|