Module: Restfulie::Client::Feature::Base

Defined in:
lib/restfulie/client/feature/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cookiesObject (readonly)

Returns the value of attribute cookies.



4
5
6
# File 'lib/restfulie/client/feature/base.rb', line 4

def cookies
  @cookies
end

#default_headersObject (readonly)

Returns the value of attribute default_headers.



4
5
6
# File 'lib/restfulie/client/feature/base.rb', line 4

def default_headers
  @default_headers
end

#headersObject



55
56
57
# File 'lib/restfulie/client/feature/base.rb', line 55

def headers
  @headers ||= {}
end

#hostObject

Returns the value of attribute host.



4
5
6
# File 'lib/restfulie/client/feature/base.rb', line 4

def host
  @host
end

#verbObject (readonly)

Returns the value of attribute verb.



4
5
6
# File 'lib/restfulie/client/feature/base.rb', line 4

def verb
  @verb
end

Instance Method Details

#accepts(content_type) ⇒ Object

Set Accept headers



24
25
26
27
# File 'lib/restfulie/client/feature/base.rb', line 24

def accepts(content_type)
  headers['Accept'] = content_type
  self
end

#as(content_type) ⇒ Object

Set Content-Type and Accept headers



18
19
20
21
# File 'lib/restfulie/client/feature/base.rb', line 18

def as(content_type)
  headers['Content-Type'] = content_type
  accepts(content_type)
end

#at(url) ⇒ Object

Set host



8
9
10
11
12
13
14
15
# File 'lib/restfulie/client/feature/base.rb', line 8

def at(url)
  if self.host.nil?
    self.host= url
  else
    self.host= self.host + url
  end
  self
end

#http_to_s(method, path, *args) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/restfulie/client/feature/base.rb', line 59

def http_to_s(method, path, *args)
  result = ["#{method.to_s.upcase} #{path}"]

  arguments = args.dup
  headers = arguments.extract_options!

  if [:post, :put].include?(method)
    body = arguments.shift
  end

  result << headers.collect { |key, value| "#{key}: #{value}" }.join("\n")

  (result + [body ? (body.inspect + "\n") : nil]).compact.join("\n") << "\n"
end

#pathObject

Path (e.g. restfulie.com/posts => /posts)



39
40
41
# File 'lib/restfulie/client/feature/base.rb', line 39

def path
  host.path + (host.query.nil? ? "" : "?#{host.query}")
end

#with(headers) ⇒ Object

Merge internal header

  • headers (e.g. {'Cache-control' => 'no-cache'})



33
34
35
36
# File 'lib/restfulie/client/feature/base.rb', line 33

def with(headers)
  headers.merge!(headers)
  self
end