url 0.1.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,8 +2,26 @@
2
2
 
3
3
  A simple url object to allow for object oriented based manipulation and usage of a url
4
4
 
5
+ == Usage
5
6
 
6
- === TODO
7
+ === Basic Usage
8
+
9
+ You can easily extract or change any part of the url
10
+
11
+ url = URL.new('https://mail.google.com/mail/?shva=1#mbox')
12
+ url.params # => {:shva => '1'}
13
+ url.scheme # => 'https'
14
+ url.host # => 'mail.google.com'
15
+ url.domain # => 'google.com'
16
+ url.subdomain # => ['mail']
17
+ url.path # => '/mail/'
18
+ url.hash # => 'mbox'
19
+
20
+ url.subdomain = ['my','mail']
21
+ url.params[:foo] = 'bar'
22
+ url.to_s # => 'https://my.mail.google.com/mail/?foo=bar&shva=1#mbox'
23
+
24
+ == TODO
7
25
  * More Documentation
8
26
  * More specs
9
27
 
data/Rakefile CHANGED
@@ -42,3 +42,12 @@ Rake::RDocTask.new do |rdoc|
42
42
  rdoc.rdoc_files.include('README*')
43
43
  rdoc.rdoc_files.include('lib/**/*.rb')
44
44
  end
45
+
46
+ begin
47
+ require 'yard'
48
+ YARD::Rake::YardocTask.new
49
+ rescue LoadError
50
+ task :yardoc do
51
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
52
+ end
53
+ end
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 0
5
- :build: 1
4
+ :patch: 1
5
+ :build:
data/lib/url.rb CHANGED
@@ -55,6 +55,8 @@ class URL
55
55
  end
56
56
 
57
57
  # Outputs the full current url
58
+ # @param [Hash<Symbol,false>,#whatever] ops Prevent certain parts of the object from being shown by setting `:scheme`,`:port`,`:path`,`:params`, or `:hash` to `false`
59
+ # @return [String]
58
60
  def to_s ops={}
59
61
  ret = String.new
60
62
  ret << %{#{scheme}://} if scheme && ops[:scheme] != false
@@ -73,6 +75,7 @@ class URL
73
75
  end
74
76
 
75
77
  # Returns the parsed URI object for the string
78
+ # @return [URI]
76
79
  def to_uri
77
80
  URI.parse(to_s)
78
81
  end
@@ -86,24 +89,31 @@ class URL
86
89
  end
87
90
 
88
91
  # Performs a get request for the current URL
92
+ # @return [URL::Response] A subclass of string which also repsonds to a few added mthods storing more information
89
93
  def get(*args)
90
94
  req_handler.get(*args)
91
95
  end
92
96
 
93
97
  # Performs a post request for the current URL
98
+ # @return [URL::Response] A subclass of string which also repsonds to a few added mthods storing more information
94
99
  def post(*args)
95
100
  req_handler.post(*args)
96
101
  end
97
102
 
98
103
  # Performs a delete request for the current URL
104
+ # @return [URL::Response] A subclass of string which also repsonds to a few added mthods storing more information
99
105
  def delete(*args)
100
106
  req_handler.delete(*args)
101
107
  end
102
108
 
109
+ def inspect #:nodoc:
110
+ "#<URL #{to_s}>"
111
+ end
112
+
103
113
  if defined?(Typhoeus)
104
- self.req_handler = TyHandler
114
+ URL.req_handler = TyHandler
105
115
  else
106
- self.req_handler = NetHandler
116
+ URL.req_handler = NetHandler
107
117
  end
108
118
  end
109
119
 
@@ -1,13 +1,13 @@
1
1
  class URL
2
2
 
3
- class Handler #:nodoc: all
3
+ class Handler
4
4
  attr_reader :url
5
5
  def initialize(url)
6
6
  @url = url
7
7
  end
8
8
  end
9
9
 
10
- class TyHandler < Handler #:nodoc: all
10
+ class TyHandler < Handler
11
11
 
12
12
  def get(args={})
13
13
  resp = Typhoeus::Request.get(url.to_s)
@@ -42,7 +42,7 @@ class URL
42
42
 
43
43
  end
44
44
 
45
- class NetHandler < Handler #:nodoc: all
45
+ class NetHandler < Handler
46
46
  def get(args={})
47
47
  puts 'net'
48
48
  http = http_obj
@@ -2,7 +2,14 @@ require "delegate"
2
2
 
3
3
  class URL
4
4
 
5
- class Response < DelegateClass(String) #:nodoc: all
5
+ # The Response class is a deleegate to string which also contains metadata about the request.
6
+ # These methods are also available
7
+ # * body
8
+ # * code - http code
9
+ # * response - the original response object from whatever handler you chose
10
+ # * time - time taken to make call
11
+ # * success? - whether the http code is 200
12
+ class Response < DelegateClass(String)
6
13
  attr_reader :body,:time,:code,:response
7
14
  def initialize(str,args={})
8
15
  if str.is_a?(Hash)
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: url
3
3
  version: !ruby/object:Gem::Version
4
- hash: 69
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
9
  - 1
11
- version: 0.1.0.1
10
+ version: 0.1.1
12
11
  platform: ruby
13
12
  authors:
14
13
  - Tal Atlas