url 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/url.rb +38 -37
  2. data/lib/url/version.rb +1 -1
  3. metadata +48 -76
data/lib/url.rb CHANGED
@@ -22,14 +22,14 @@ files.each { |f| require File.join(File.dirname(__FILE__),'url',f) }
22
22
  # url.subdomain # => ['mail']
23
23
  # url.path # => '/mail/'
24
24
  # url.hash # => 'mbox'
25
- #
25
+ #
26
26
  # url.subdomain = ['my','mail']
27
27
  # url.params[:foo] = 'bar'
28
28
  # url.to_s # => 'https://my.mail.google.com/mail/?foo=bar&shva=1#mbox'
29
29
  class URL
30
30
  extend Forwardable
31
31
  attr_reader :string
32
-
32
+
33
33
  # The params for the request
34
34
  # @returns [URL::ParamsHash]
35
35
  attr_reader :params
@@ -41,21 +41,21 @@ class URL
41
41
  raise ArgumentError, 'Params must be a URL::ParamsHash' unless p.is_a?(ParamsHash)
42
42
  @params = p
43
43
  end
44
-
44
+
45
45
  # Attributes of the URL which are editable
46
46
  # @returns [String]
47
47
  attr_accessor :domain, :scheme, :format, :port, :hash
48
-
48
+
49
49
  # The path for the request
50
50
  # @returns [URL::Path]
51
51
  attr_reader :path
52
-
52
+
53
53
  # Set the path for the request
54
54
  def path=str
55
55
  if str.nil? || str.empty?
56
56
  str = '/'
57
57
  end
58
-
58
+
59
59
  @path = str
60
60
  end
61
61
 
@@ -67,22 +67,22 @@ class URL
67
67
  @path << val.sub(/^\//,'')
68
68
  @path
69
69
  end
70
-
70
+
71
71
  # Returns array of subdomains
72
72
  # @returns [URL::Subdomain]
73
73
  attr_reader :subdomain
74
74
  alias_method :subdomains, :subdomain
75
-
75
+
76
76
  # @param [Array,String] subdomain An array or string for subdomain
77
77
  def subdomain=(s)
78
78
  if s.is_a?(String)
79
79
  s = s.split('.')
80
80
  end
81
-
81
+
82
82
  @subdomain = s
83
83
  end
84
84
  alias_method :subdomains=, :subdomain=
85
-
85
+
86
86
  # Creates a new URL object
87
87
  # @param [String] URL the starting url to work with
88
88
  def initialize str
@@ -93,16 +93,17 @@ class URL
93
93
  self.path = sp[5]
94
94
  @format = @path.gsub(/(.+\.)/,'')
95
95
  @hash = sp[8]
96
-
96
+
97
97
  if sp[2]
98
98
  host_parts = sp[2].split('.')
99
- if host_parts[-2] == 'co'
99
+ # Detect internationl urls and treat as tld (eg .co.uk)
100
+ if host_parts[-2] == 'co' and host_parts.length > 2
100
101
  @domain = host_parts[-3,3].join('.')
101
102
  @subdomain = host_parts.first(host_parts.length-3)
102
103
  else
103
104
  begin
104
105
  @domain = host_parts[-2,2].join('.')
105
- @subdomain = host_parts.first(host_parts.length-2)
106
+ @subdomain = host_parts.first(host_parts.length-2)
106
107
  rescue # if there arent at least 2 parts eg: localhost
107
108
  @domain = host_parts.join('.')
108
109
  end
@@ -111,7 +112,7 @@ class URL
111
112
  @domain = nil
112
113
  @subdomain = nil
113
114
  end
114
-
115
+
115
116
  @params = ParamsHash.new
116
117
  if sp[7]
117
118
  sp[7].gsub('?','').split('&').each do |myp|
@@ -121,9 +122,9 @@ class URL
121
122
  end
122
123
  end
123
124
  end
124
-
125
+
125
126
  def_delegators :@params, :[], :[]=
126
-
127
+
127
128
  # The full hostname (not including port) for the URL
128
129
  def host
129
130
  [@subdomain,@domain].flatten.compact.join('.')
@@ -133,7 +134,7 @@ class URL
133
134
  def host_with_port
134
135
  host<<':'<<port.to_s
135
136
  end
136
-
137
+
137
138
  # Outputs the full current url
138
139
  # @param [Hash] ops Prevent certain parts of the object from being shown by setting `:scheme`,`:port`,`:path`,`:params`, or `:hash` to `false`
139
140
  # @return [String]
@@ -145,33 +146,33 @@ class URL
145
146
  if path && ops[:path] != false
146
147
  ret << path
147
148
  end
148
-
149
+
149
150
  ret << params.to_s if params && ops[:params] != false
150
-
151
+
151
152
  ret << "##{hash.to_s}" if hash && ops[:hash] != false
152
-
153
+
153
154
  ret
154
155
  end
155
-
156
+
156
157
  # Returns the parsed URI object for the string
157
158
  # @return [URI]
158
159
  def to_uri
159
160
  URI.parse(to_s)
160
161
  end
161
-
162
+
162
163
  class << self
163
164
  # Define the request handler to use. If Typhoeus is setup it will use {TyHandler} otherwise will default back to Net::HTTP with {NetHandler}
164
165
  # @return [RequstHandler]
165
166
  def req_handler
166
167
  return @req_handler if @req_handler
167
-
168
+
168
169
  if defined?(Typhoeus)
169
170
  URL.req_handler = URL::TyHandler
170
171
  else
171
172
  URL.req_handler = URL::NetHandler
172
173
  end
173
174
  end
174
-
175
+
175
176
  # Define the request handler to use. If Typhoeus is setup it will use {TyHandler} otherwise will default back to Net::HTTP with {NetHandler}
176
177
  # @param [RequstHandler]
177
178
  # @return [RequstHandler]
@@ -179,10 +180,10 @@ class URL
179
180
  raise ArgumentError, 'Must be a subclass of URL::RequestHandler' unless r.nil? || r < RequestHandler
180
181
  @req_handler = r
181
182
  end
182
-
183
+
183
184
  def json_handler
184
185
  return @json_handler if @json_handler
185
-
186
+
186
187
  if defined?(Yajl)
187
188
  URL.json_handler = URL::YajlHandler
188
189
  elsif defined?(JSON)
@@ -191,25 +192,25 @@ class URL
191
192
  URL.json_handler = URL::ASJSONHandler
192
193
  end
193
194
  end
194
-
195
+
195
196
  def json_handler=r
196
197
  raise ArgumentError, 'Must be a subclass of URL::JSONHandler' unless r.nil? || r < JSONHandler
197
198
  @json_handler = r
198
199
  end
199
200
  end
200
-
201
+
201
202
  # Performs a get request for the current URL
202
203
  # @return [URL::Response] A subclass of string which also repsonds to a few added mthods storing more information
203
204
  def get(*args)
204
205
  req_handler.get(*args)
205
206
  end
206
-
207
+
207
208
  # Performs a post request for the current URL
208
209
  # @return [URL::Response] A subclass of string which also repsonds to a few added mthods storing more information
209
210
  def post(*args)
210
211
  req_handler.post(*args)
211
212
  end
212
-
213
+
213
214
  # Performs a delete request for the current URL
214
215
  # @return [URL::Response] A subclass of string which also repsonds to a few added mthods storing more information
215
216
  def delete(*args)
@@ -221,25 +222,25 @@ class URL
221
222
  def put(*args)
222
223
  req_handler.delete(*args)
223
224
  end
224
-
225
+
225
226
  def inspect
226
227
  "#<#{self.class} #{to_s}>"
227
228
  end
228
-
229
+
229
230
  def dup
230
231
  URL.new(to_s)
231
232
  end
232
-
233
- # The request handler for this
233
+
234
+ # The request handler for this
234
235
  # @return [Handler]
235
236
  def req_handler
236
237
  (@req_handler||self.class.req_handler).new(self)
237
238
  end
238
-
239
+
239
240
  def =~ reg
240
241
  to_s =~ reg
241
242
  end
242
-
243
+
243
244
  # Sets the handler to use for this request
244
245
  # @param [RequstHandler]
245
246
  # @return [RequstHandler]
@@ -247,6 +248,6 @@ class URL
247
248
  raise ArgumentError, 'Must be a subclass of URL::Handler' unless r < RequestHandler
248
249
  @req_handler = r
249
250
  end
250
-
251
+
251
252
  end
252
253
 
@@ -1,3 +1,3 @@
1
1
  class URL
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,76 +1,58 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: url
3
- version: !ruby/object:Gem::Version
4
- hash: 17
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Tal Atlas
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-07-25 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- prerelease: false
22
- type: :development
23
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2011-07-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70179099658740 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 7
29
- segments:
30
- - 2
31
- version: "2"
32
- name: rspec
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- prerelease: false
20
+ - !ruby/object:Gem::Version
21
+ version: '2'
36
22
  type: :development
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
46
- name: rake
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
23
  prerelease: false
24
+ version_requirements: *70179099658740
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70179099658320 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
50
33
  type: :development
51
- requirement: &id003 !ruby/object:Gem::Requirement
34
+ prerelease: false
35
+ version_requirements: *70179099658320
36
+ - !ruby/object:Gem::Dependency
37
+ name: yard
38
+ requirement: &70179099657740 !ruby/object:Gem::Requirement
52
39
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 1
57
- segments:
58
- - 0
59
- - 7
60
- - 1
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
61
43
  version: 0.7.1
62
- name: yard
63
- version_requirements: *id003
64
- description: A simple url object to allow for OO based manipulation and usage of a url
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70179099657740
47
+ description: A simple url object to allow for OO based manipulation and usage of a
48
+ url
65
49
  email: me@tal.by
66
50
  executables: []
67
-
68
51
  extensions: []
69
-
70
- extra_rdoc_files:
52
+ extra_rdoc_files:
71
53
  - LICENSE
72
54
  - README.rdoc
73
- files:
55
+ files:
74
56
  - lib/url/accepts_endpoint.rb
75
57
  - lib/url/classer.rb
76
58
  - lib/url/endpoint.rb
@@ -98,36 +80,26 @@ files:
98
80
  - Rakefile
99
81
  homepage: http://github.com/talby/url
100
82
  licenses: []
101
-
102
83
  post_install_message:
103
84
  rdoc_options: []
104
-
105
- require_paths:
85
+ require_paths:
106
86
  - lib
107
- required_ruby_version: !ruby/object:Gem::Requirement
87
+ required_ruby_version: !ruby/object:Gem::Requirement
108
88
  none: false
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- hash: 3
113
- segments:
114
- - 0
115
- version: "0"
116
- required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
94
  none: false
118
- requirements:
119
- - - ">="
120
- - !ruby/object:Gem::Version
121
- hash: 3
122
- segments:
123
- - 0
124
- version: "0"
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
125
99
  requirements: []
126
-
127
100
  rubyforge_project:
128
- rubygems_version: 1.8.8
101
+ rubygems_version: 1.8.16
129
102
  signing_key:
130
103
  specification_version: 3
131
104
  summary: A URL object
132
105
  test_files: []
133
-