sinatra_client 0.0.2 → 0.0.3

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: 34cf7b797e39965e332c89a585c9c773964fa3a8df4e8fd293dab2f9354d8da7
4
- data.tar.gz: 21c6b5ea4209493bffdd3d6f0215bb3c18663e32f0fff3e29fd51f901f5e0408
3
+ metadata.gz: c7984f90bf4b0773630471d9245b4938603bddeb5df3eadd56751d184f15f1f3
4
+ data.tar.gz: 7f7727bf4f42eaa8cf60ac4cb217cd8f96be92c6ae6da7576df3003236fad217
5
5
  SHA512:
6
- metadata.gz: 97cdd11e82b2d4ef595f0f7c93c856d8d7a8ebfe18bd583ef26ebeae1ddd76f77df9bd1ce22a36c6767ce90045572bbfb2b76ed3ae2884c2270f395de7236547
7
- data.tar.gz: 75ce8e3f7c470e9458bf0867f79d7e34b2bfdad693cb05693474baf3999914a066efc950fbd3309217db6f72211dc5501e331feaea7b3a752d8c59d3f800f190
6
+ metadata.gz: 2c77381e61384032c8a82c18fa7cace08d2d3aa4003dfd4df6aff8b01911cbbedf1c028042d8d6dc2c9fd1f7badfd608c2fb4bc7f352628037c728a15d8a954c
7
+ data.tar.gz: 12f9c08ce23f8686d3d28f6195647b3795c273595eb872471e1774216648470e1b94b2bfc3098238c1de9d4d7da6dd3fdd18aa0150fbca936d6bf337a0d83135
@@ -4,73 +4,68 @@ require "dotenv/load"
4
4
  require 'uri'
5
5
 
6
6
  class SinatraClient
7
- attr_accessor :current_user_id, :url, :auth
7
+ attr_accessor :current_user_id, :url
8
8
 
9
9
  def initialize(current_user_id = nil)
10
10
  @current_user_id = current_user_id
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
11
+ @url = URI::HTTP.build(userinfo: "#{ENV['API_NAME']}:#{ENV['API_PASSWORD']}", host: ENV['SINATRA_HOST'], port: ENV['SINATRA_PORT'], path: '/api/v1')
13
12
  end
14
13
 
15
14
  def get_user_posts(user_id)
16
15
  url.path << "/users/#{user_id}/posts"
17
- parse RestClient.get(url.to_s, auth_header)
16
+ parse RestClient.get(url.to_s)
18
17
  end
19
18
 
20
19
  def create_post(post)
21
20
  url.path << '/posts'
22
- parse RestClient.post(url.to_s, post, auth_header)
21
+ parse RestClient.post(url.to_s, post)
23
22
  end
24
23
 
25
24
  def delete_post(post_id)
26
25
  url.path << "/posts/#{post_id}"
27
26
  url.query = URI.encode_www_form({ current_user: current_user_id })
28
- parse RestClient.delete(url.to_s, auth_header)
27
+ parse RestClient.delete(url.to_s)
29
28
  end
30
29
 
31
30
  def delete_posts_for(postable_id, postable_type)
32
31
  url.path << "/postable/#{postable_id}/posts"
33
32
  url.query = URI.encode_www_form({ postable_type: postable_type })
34
- parse RestClient.delete(url.to_s, auth_header)
33
+ parse RestClient.delete(url.to_s)
35
34
  end
36
35
 
37
36
  def get_group_posts(group_id)
38
37
  url.path << "/groups/#{group_id}/posts"
39
- parse RestClient.get(url.to_s, auth_header)
38
+ parse RestClient.get(url.to_s)
40
39
  end
41
40
 
42
41
  def get_user_posts_comment(post_id)
43
42
  url.path << "/posts/#{post_id}/comments"
44
- parse RestClient.get(url.to_s, auth_header)
43
+ parse RestClient.get(url.to_s)
45
44
  end
46
45
 
47
46
  def create_comment_for_post(post_id, comment)
48
47
  url.path << "/posts/#{post_id}/comments"
49
- parse RestClient.post(url.to_s, comment, auth_header)
48
+ parse RestClient.post(url.to_s, comment)
50
49
  end
51
50
 
52
51
  def delete_comment(post_id, comment_guid)
53
52
  url.path << "/posts/#{post_id}/comments/#{comment_guid}"
54
53
  url.query = URI.encode_www_form({ current_user: current_user_id })
55
- parse RestClient.delete(url.to_s, auth_header)
54
+ parse RestClient.delete(url.to_s)
56
55
  end
57
56
 
58
57
  def create_or_delete_like(post_id, liker_id)
59
58
  url.path << "/posts/#{post_id}/toggle_like"
60
- parse RestClient.post(url.to_s, liker_id, auth_header)
59
+ parse RestClient.post(url.to_s, liker_id)
61
60
  end
62
61
 
63
62
  def get_likers(post_id)
64
63
  url.path << "/posts/#{post_id}/likers"
65
- parse RestClient.get(url.to_s, auth_header)
64
+ parse RestClient.get(url.to_s)
66
65
  end
67
66
 
68
67
  private
69
68
 
70
- def auth_header
71
- { Authorization: auth }
72
- end
73
-
74
69
  def parse(response)
75
70
  JSON.parse(response.body)
76
71
  end
@@ -1,3 +1,3 @@
1
1
  class SinatraClient
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
Binary file
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.2
4
+ version: 0.0.3
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-19 00:00:00.000000000 Z
11
+ date: 2021-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -60,6 +60,7 @@ files:
60
60
  - lib/sinatra_client.rb
61
61
  - lib/sinatra_client/version.rb
62
62
  - sinatra_client-0.0.1.gem
63
+ - sinatra_client-0.0.2.gem
63
64
  - sinatra_client.gemspec
64
65
  homepage:
65
66
  licenses: