hayamichi 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 +7 -0
- data/lib/hayamichi.rb +36 -0
- data/lib/hayamichi_response.rb +36 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 95fb5ddacf61ed3b261dcb635572a98bff0e7a1c
|
4
|
+
data.tar.gz: d28efb092db015d9e5efadf715c55e48f9f93708
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8f81183e74f6d3ff9a20b8bcbd9af70c6c4c1f96ddc43144c509fde3d6e588823c798c8467d7beed16809b083e6ce15d8e9b30172172640bd2eafdc24c85b149
|
7
|
+
data.tar.gz: c61888abc8f722f8573484854d410202a0ae1312a567684d06c8f237493e37fdbf3a1449cae55dd725792ea3a1c4e73d3af0d40a0fe61734c7dca9259a9effe0
|
data/lib/hayamichi.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'hayamichi_constants'
|
2
|
+
require_relative 'hayamichi_response'
|
3
|
+
|
4
|
+
require 'uri'
|
5
|
+
require 'net/http'
|
6
|
+
|
7
|
+
class Hayamichi
|
8
|
+
attr_accessor :uri, :method, :data
|
9
|
+
attr_reader :data
|
10
|
+
|
11
|
+
def initialize(uri, hash = { method: :post })
|
12
|
+
raise INVALID_URI_ERROR unless uri =~ URI::regexp
|
13
|
+
@uri = URI(uri)
|
14
|
+
|
15
|
+
@method = hash[:method]
|
16
|
+
raise INVALID_METHOD_ERROR unless ALLOWED_METHODS.include? @method
|
17
|
+
end
|
18
|
+
|
19
|
+
def submit
|
20
|
+
raise DATA_NIL_ERROR if @data.nil?
|
21
|
+
|
22
|
+
if @method == POST
|
23
|
+
response = Net::HTTP.post_form @uri, @data
|
24
|
+
else
|
25
|
+
uri = uri_for_get @uri, @data
|
26
|
+
response = Net::HTTP.get uri
|
27
|
+
end
|
28
|
+
|
29
|
+
Response.new(response)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def uri_for_get uri, data
|
34
|
+
parsed = URI(uri)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
class Hayamichi
|
5
|
+
class Response
|
6
|
+
attr_reader :status, :url, :data, :response
|
7
|
+
|
8
|
+
def initialize(response)
|
9
|
+
@status, @url, @data = false, '', {}
|
10
|
+
@response = response # raw response
|
11
|
+
|
12
|
+
raise INVALID_RESPONSE_ERROR unless @response.respond_to? :status
|
13
|
+
|
14
|
+
# parse status here then is success
|
15
|
+
case response
|
16
|
+
when Net::HTTPSuccess then
|
17
|
+
@status = true
|
18
|
+
when Net::HTTPRedirection then
|
19
|
+
@status = true
|
20
|
+
redirect = response['location']
|
21
|
+
if redirect != ''
|
22
|
+
uri = URI redirect
|
23
|
+
@url = url_from_uri uri
|
24
|
+
@data = URI.decode_www_form(uri.query).to_h
|
25
|
+
end
|
26
|
+
else
|
27
|
+
@status = false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def url_from_uri uri
|
33
|
+
"#{uri.scheme}://#{uri.host}#{uri.path}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hayamichi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oscar Moreno Garza
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: ozkar@ozkar.org
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/hayamichi.rb
|
20
|
+
- lib/hayamichi_response.rb
|
21
|
+
homepage: http://github.com/ozkar99/hayamichi
|
22
|
+
licenses:
|
23
|
+
- BSD 2-Clause
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.6.14
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: A redirect-submit-redirectback circumventer
|
45
|
+
test_files: []
|