lucid_http 0.11.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c3d89cfb05f3e19b063b49656ab41d7b55d3c493
4
- data.tar.gz: 4187068a6b4c10d59697dedd2258076c615d58f1
2
+ SHA256:
3
+ metadata.gz: 86839bf1b17b757a0a6d13320012b5bb70006baea5a7142aeddac5e61413b200
4
+ data.tar.gz: 7f3076b7f572687710b163eea2f8aa64e8215b6095a6dbc7d8af2cf63ab8d266
5
5
  SHA512:
6
- metadata.gz: d9fd3f7f7af0dd63e9c1c82be3867814ff34ce201fe3ae952bf09aada906889817766d81c080fee510d3055bceb0e869ad897a33fd0079cb2f832272f58d962a
7
- data.tar.gz: c6750975060769f0704a6b1da6b86d2e22f4bebfa001eaada0b6c1e18e5c4cbce2b134b32a4aa03648cd74adc34100b28fa1e78ba1b76c24547404161e00b688
6
+ metadata.gz: 2fad8f9890cddcdcb9ee7e018f2bcb63dc779074b5fcea70126f441e4ef6843b956a228c11ec2ad70296a414f9fe9f1175aa8d867245c41a3285d3bf7fd6ce1e
7
+ data.tar.gz: b98dc998c2e7332a6326ee54fb4dcd7f7176ab1e2056605288e43d97a7396d46b5185fab0b3cf9d1f46e2d3a0f118cc995ea59990418c5a679be9b970919fbc5
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --color
3
+ --format=progress
@@ -0,0 +1,25 @@
1
+ module LucidHttp
2
+
3
+ module Follower
4
+
5
+ def self.for(keyword)
6
+ {
7
+ no_follow: NoFollow.new,
8
+ follow: Follow.new,
9
+ }.fetch(keyword)
10
+ end
11
+
12
+ class NoFollow
13
+ def client
14
+ HTTP
15
+ end
16
+ end
17
+
18
+ class Follow
19
+ def client
20
+ HTTP.follow
21
+ end
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,26 @@
1
+ require "json"
2
+ module LucidHttp
3
+
4
+ module Formatter
5
+
6
+ def self.for(keyword)
7
+ {
8
+ plain: PlainFormatter.new,
9
+ json: JsonFormatter.new,
10
+ }.fetch(keyword)
11
+ end
12
+
13
+ class PlainFormatter
14
+ def call(response_body)
15
+ response_body
16
+ end
17
+ end
18
+
19
+ class JsonFormatter
20
+ def call(response_body)
21
+ JSON.parse(response_body)
22
+ end
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,41 @@
1
+ module LucidHttp
2
+ class Response
3
+ attr_reader :base_url
4
+ attr_reader :path
5
+
6
+ def initialize(base_url:, path:, formatter:, follower:, verb: :get, form: {})
7
+ @base_url = base_url
8
+ @path = path
9
+ @formatter = LucidHttp::Formatter.for(formatter)
10
+ @follower = LucidHttp::Follower.for(follower).client
11
+ @verb = verb
12
+ @form = form
13
+
14
+ @response = @follower.send(@verb, url, params: form)
15
+ end
16
+
17
+ def body
18
+ @formatter.call(@response.body.to_s)
19
+ end
20
+
21
+ def status
22
+ @response.status.to_s
23
+ end
24
+
25
+ def content_type
26
+ @response.content_type.mime_type
27
+ end
28
+
29
+ def url
30
+ "#{base_url}#{path}"
31
+ end
32
+
33
+ def error
34
+ body.split("\n").first
35
+ end
36
+
37
+ def verb
38
+ @verb.to_s.upcase
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module LucidHttp
2
- VERSION = "0.11.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/lucid_http.rb CHANGED
@@ -1,100 +1,71 @@
1
1
  require "lucid_http/version"
2
2
  require "http"
3
- require "delegate"
4
- require "json"
3
+ require "lucid_http/followers"
4
+ require "lucid_http/formatters"
5
+ require "lucid_http/response"
5
6
 
6
7
  module LucidHttp
7
- def self.target_url
8
- @target_url ||= ENV.fetch("TARGET_URL") { "http://localhost:9292" }
9
- end
10
-
11
- def self.target_url=(url="http://localhost:9292")
12
- @target_url = url
13
- end
8
+ class Client
9
+ attr_reader :base_url
14
10
 
15
- class PrettyStatus < SimpleDelegator
16
- def inspect
17
- to_s
11
+ def initialize(base_url:)
12
+ @base_url = base_url
18
13
  end
19
- end
20
- end
21
14
 
22
- def response
23
- @__lucid_http__res
24
- end
15
+ %i[get post put patch delete options].each do |verb|
16
+ define_method(verb.upcase) do |path, formatter: :plain, follower: :no_follow, form: {}|
17
+ do_verb(
18
+ verb: verb, path: path,
19
+ formatter: formatter, follower: follower,
20
+ form: form,
21
+ )
22
+ end
23
+ end
25
24
 
26
- def __lucid_http__clean
27
- instance_variables.grep(/@__lucid_http__/).each do |v|
28
- remove_instance_variable(v.to_sym)
25
+ def do_verb(verb:, path:, formatter:, follower:, form:)
26
+ LucidHttp::Response.new(
27
+ base_url: base_url, path: path, verb: verb,
28
+ formatter: formatter, follower: follower,
29
+ form: form,
30
+ )
31
+ end
29
32
  end
30
33
  end
31
34
 
32
- def __lucid_http__setup(url, action: :get, follow: false, form: nil, json: false, **opts)
33
- __lucid_http__clean
34
- @__lucid_http__client = HTTP.persistent(LucidHttp.target_url)
35
- if follow
36
- @__lucid_http__client = @__lucid_http__client.follow
35
+ %i[get post put patch delete options].each do |verb|
36
+ define_method(verb.upcase) do |path, formatter: :plain, follower: :no_follow, form: {}|
37
+ @__response = LucidHttp::Client.new(base_url: "http://localhost:9292").do_verb(
38
+ verb: verb, path: path,
39
+ formatter: formatter, follower: follower,
40
+ form: form,
41
+ )
37
42
  end
38
- @__lucid_http__path = @__lucid_http__client.default_options.persistent + url
39
- @__lucid_http__res = @__lucid_http__client.send(action.to_sym, url, form: form)
40
- @__lucid_http__json = json
41
43
  end
42
44
 
43
45
  def body
44
- @__lucid_http__body ||= __lucid_http__get_body
46
+ @__response.body
45
47
  end
46
48
 
47
- def __lucid_http__get_body
48
- original_body = response.body.to_s
49
- if !@__lucid_http__json
50
- original_body
51
- else
52
- JSON.parse(original_body)
53
- end
49
+ def verb
50
+ @__response.verb
54
51
  end
55
52
 
56
53
  def status
57
- @__lucid_http__status = LucidHttp::PrettyStatus.new(response.status)
54
+ @__response.status
58
55
  end
59
56
 
60
57
  def content_type
61
- response.content_type.mime_type
58
+ @__response.content_type
62
59
  end
63
60
 
64
- def path
65
- @__lucid_http__path
61
+ def url
62
+ @__response.url
66
63
  end
67
64
 
68
- def error
69
- if status.to_i == 500
70
- body.split("\n").first
71
- else
72
- "No 500 error found."
73
- end
65
+ def path
66
+ @__response.path
74
67
  end
75
68
 
76
- %i[get post put patch delete head options].each do |verb|
77
- define_method(verb.upcase) do |url, **opts|
78
- __lucid_http__setup(url, action: verb, **opts)
79
- new_body = case status.to_i
80
- when 200
81
- body
82
- else
83
- "STATUS: #{status}"
84
- end
85
-
86
- new_body
87
- end
69
+ def error
70
+ @__response.error
88
71
  end
89
-
90
- # def POST(url, **opts)
91
- # __lucid_http__setup(url, action: :post, **opts)
92
- # new_body = case status.to_i
93
- # when 200
94
- # body
95
- # else
96
- # "STATUS: #{status}"
97
- # end
98
-
99
- # new_body
100
- # end
data/lucid_http.gemspec CHANGED
@@ -21,9 +21,11 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_runtime_dependency "http", "~> 2.1"
24
+ spec.add_runtime_dependency "http"
25
25
 
26
- spec.add_development_dependency "bundler", "~> 1.13"
27
- spec.add_development_dependency "rake", "~> 10.0"
28
- spec.add_development_dependency "minitest", "~> 5.0"
26
+ spec.add_development_dependency "rackup", "~> 2.1.0"
27
+ spec.add_development_dependency "rake", "~> 13.0.6"
28
+ spec.add_development_dependency "roda", "~> 3.66.0"
29
+ spec.add_development_dependency "rspec", "~> 3.12.0"
30
+ spec.add_development_dependency "bundler", "~> 2.4.8"
29
31
  end
metadata CHANGED
@@ -1,71 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucid_http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Federico Iachetti
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-31 00:00:00.000000000 Z
11
+ date: 2023-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.1'
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '2.1'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: rackup
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.13'
33
+ version: 2.1.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.13'
40
+ version: 2.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: 13.0.6
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 13.0.6
55
+ - !ruby/object:Gem::Dependency
56
+ name: roda
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.66.0
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '10.0'
68
+ version: 3.66.0
55
69
  - !ruby/object:Gem::Dependency
56
- name: minitest
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.12.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.12.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
87
  - - "~>"
60
88
  - !ruby/object:Gem::Version
61
- version: '5.0'
89
+ version: 2.4.8
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
94
  - - "~>"
67
95
  - !ruby/object:Gem::Version
68
- version: '5.0'
96
+ version: 2.4.8
69
97
  description: Lucid Http wraps the http.rb gem in a simple DSL. Is particularly useful
70
98
  for screencasts and simple presentations.
71
99
  email:
@@ -75,6 +103,7 @@ extensions: []
75
103
  extra_rdoc_files: []
76
104
  files:
77
105
  - ".gitignore"
106
+ - ".rspec"
78
107
  - ".travis.yml"
79
108
  - CODE_OF_CONDUCT.md
80
109
  - Gemfile
@@ -84,13 +113,16 @@ files:
84
113
  - bin/console
85
114
  - bin/setup
86
115
  - lib/lucid_http.rb
116
+ - lib/lucid_http/followers.rb
117
+ - lib/lucid_http/formatters.rb
118
+ - lib/lucid_http/response.rb
87
119
  - lib/lucid_http/version.rb
88
120
  - lucid_http.gemspec
89
121
  homepage: https://github.com/iachettifederico/lucid_http
90
122
  licenses:
91
123
  - MIT
92
124
  metadata: {}
93
- post_install_message:
125
+ post_install_message:
94
126
  rdoc_options: []
95
127
  require_paths:
96
128
  - lib
@@ -105,9 +137,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
137
  - !ruby/object:Gem::Version
106
138
  version: '0'
107
139
  requirements: []
108
- rubyforge_project:
109
- rubygems_version: 2.6.8
110
- signing_key:
140
+ rubygems_version: 3.4.8
141
+ signing_key:
111
142
  specification_version: 4
112
143
  summary: Lucid Http wraps the http.rb gem in a simple DSL.
113
144
  test_files: []