richard_iii 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/lib/richard_iii/version.rb +1 -1
- data/test/the_basics.rb +59 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2778cafda0e669461d11038fb18214895b8718f7
|
4
|
+
data.tar.gz: 1011b06506a60f98edaf3d980e37b3d43d143cc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 547792d0cf8db701e128bd41ea1de9ad9e7b05caa3751d6811a322556cfbe50efa7aa2ee443a6841ae666030f52e7be8e5ad02d494c0206e9a1be9ac77aca85d
|
7
|
+
data.tar.gz: aa0bd33e8d43f0116cc838c83f2549c119e3dce4548ac288adf1af9ea07ed42276318d6218495b892e88e0260b6e00626439c524372543ca4932d31f92e74c3a
|
data/lib/richard_iii/version.rb
CHANGED
data/test/the_basics.rb
CHANGED
@@ -1,20 +1,74 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require 'minitest/pride'
|
3
3
|
|
4
|
+
module Richard
|
5
|
+
module Internal
|
6
|
+
class RequestLineParser
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
class RequestLine
|
11
|
+
attr_reader :method, :uri
|
12
|
+
|
13
|
+
def initialize(opts = {})
|
14
|
+
@method,@uri = opts[:method],opts[:uri]
|
15
|
+
end
|
16
|
+
|
17
|
+
def eql?(other)
|
18
|
+
return self.method == other.method && self.uri == other.uri
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module Richard
|
25
|
+
class III
|
26
|
+
def initialize(opts={})
|
27
|
+
@internet = opts[:internet] || fail("You need to supply :internet")
|
28
|
+
end
|
29
|
+
|
30
|
+
def exec(text)
|
31
|
+
lines = text.lines.map(&:chomp)
|
32
|
+
|
33
|
+
verb = lines.first.match(/^(\w+)/)[1]
|
34
|
+
path = lines.first.match(/(\S+)$/)[1]
|
35
|
+
host = lines[1].match(/Host: (.+)$/)[1]
|
36
|
+
|
37
|
+
@internet.execute Request.new(:verb => verb, :uri => "https://#{host}#{path}")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Request
|
43
|
+
attr_reader :verb, :uri
|
44
|
+
|
45
|
+
def initialize(opts={})
|
46
|
+
@verb,@uri = opts[:verb],opts[:uri]
|
47
|
+
end
|
48
|
+
|
49
|
+
def eql?(other)
|
50
|
+
self.verb.eql?(other.verb) && self.uri.eql?(other.uri)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
4
54
|
describe 'The basics of Richard III' do
|
5
55
|
it "can issue a very simple request" do
|
6
56
|
spy_internet = MiniTest::Mock.new
|
7
57
|
|
8
|
-
spy_internet.expect :execute, nil
|
58
|
+
spy_internet.expect :execute, nil do |actual|
|
59
|
+
actual.first.eql? Request.new(:verb => 'GET', :uri => 'https://api.twitter.com/1.1/statuses')
|
60
|
+
end
|
9
61
|
|
10
|
-
richard_iii = Richard::III.new spy_internet
|
62
|
+
richard_iii = Richard::III.new :internet => spy_internet
|
11
63
|
|
12
64
|
richard_iii.exec <<-TEXT
|
13
|
-
|
14
|
-
|
15
|
-
|
65
|
+
GET /1.1/statuses
|
66
|
+
Host: api.twitter.com
|
67
|
+
Accept: application/json
|
16
68
|
TEXT
|
17
69
|
|
18
70
|
spy_internet.verify
|
19
71
|
end
|
72
|
+
|
73
|
+
# TEST: where does it read the protocol part (HTTP of HTTPS)
|
20
74
|
end
|