Module: Weary
- Defined in:
- lib/weary.rb,
lib/weary/request.rb,
lib/weary/resource.rb,
lib/weary/response.rb,
lib/weary/exceptions.rb
Defined Under Namespace
Classes: HTTPError, Request, Resource, Response
Constant Summary
collapse
- Methods =
{ :get => [:get, :GET, /\bget\b/i],
:post => [:post, :POST, /\bpost\b/i],
:put => [:put, :PUT, /\bput\b/i],
:delete => [:delete, :del, :DELETE, :DEL, /\bdelete\b/i],
:head => [:head, :HEAD, /\bhead\b/i] }
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain.
34
35
36
|
# File 'lib/weary.rb', line 34
def domain
@domain
end
|
#resources ⇒ Object
Returns the value of attribute resources.
34
35
36
|
# File 'lib/weary.rb', line 34
def resources
@resources
end
|
Class Method Details
.Query(url) ⇒ Object
Weary::Query quickly performs a :get request on a URL and parses the request
29
30
31
32
|
# File 'lib/weary.rb', line 29
def self.Query(url)
req = Weary::Request.new(url, :get).perform
req.parse
end
|
Instance Method Details
43
44
45
|
# File 'lib/weary.rb', line 43
def as_format(format)
@default_format = format.to_sym
end
|
#authenticates_with(username, password) ⇒ Object
53
54
55
56
57
|
# File 'lib/weary.rb', line 53
def authenticates_with(username,password)
@username = username
@password = password
return nil
end
|
#construct_url(pattern) ⇒ Object
Also known as:
url=
48
49
50
|
# File 'lib/weary.rb', line 48
def construct_url(pattern)
@url_pattern = pattern.to_s
end
|
#declare_resource(resource, options = {}) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/weary.rb', line 59
def declare_resource(resource, options={})
@resources ||= []
r = Weary::Resource.new(resource, set_defaults(options))
declaration = r.to_hash
@resources << declaration
craft_methods(r)
return declaration
end
|
#delete(resource, options = {}) ⇒ Object
96
97
98
99
|
# File 'lib/weary.rb', line 96
def delete(resource,options={})
options[:via] = :delete
declare_resource(resource,options)
end
|
#get(resource, options = {}) ⇒ Object
81
82
83
84
|
# File 'lib/weary.rb', line 81
def get(resource,options={})
options[:via] = :get
declare_resource(resource,options)
end
|
#on_domain(domain) ⇒ Object
Also known as:
domain=
36
37
38
39
40
|
# File 'lib/weary.rb', line 36
def on_domain(domain)
parse_domain = URI.(domain)
raise ArgumentError, 'The domain must be a URL.' if parse_domain.empty?
@domain = parse_domain[0]
end
|
#post(resource, options = {}) ⇒ Object
86
87
88
89
|
# File 'lib/weary.rb', line 86
def post(resource,options={})
options[:via] = :post
declare_resource(resource,options)
end
|
#put(resource, options = {}) ⇒ Object
91
92
93
94
|
# File 'lib/weary.rb', line 91
def put(resource,options={})
options[:via] = :put
declare_resource(resource,options)
end
|