Class: Daylife::API
- Inherits:
-
Object
- Object
- Daylife::API
- Defined in:
- lib/daylife/base.rb
Overview
DayPI 101: developer.daylife.com/docs/DayPI101
The DayPI call responses include codes indicating success or failure as well as a message with some explanation or helpful tip in cases of failure. For acurrent list of response/error codes and messages, see developer.daylife.com/docs/Response_Error_Codes
Sample Usage
Daylife.authenticate('8befa1cf0a7c0291613242235638a662', '2e548ef751397c653752057adcff0c9f')
articles = Daylife::Article.('03cV5zI2fk03s')
Constant Summary collapse
- @@auth =
{ :accesskey => '', :shared_secret => '' }
Class Method Summary collapse
- .auth ⇒ Object
-
.get(method, parameters = {}) ⇒ Object
Make a get request to the input method with a parameters hash.
-
.methodize(method) ⇒ Object
Creates a Daylife style method name from a symbol.
Instance Method Summary collapse
-
#initialize(props = {}) ⇒ API
constructor
A new instance of API.
Constructor Details
#initialize(props = {}) ⇒ API
Returns a new instance of API.
35 36 37 38 39 40 |
# File 'lib/daylife/base.rb', line 35 def initialize(props={}) props.each do |key, val| setter = "#{key}=".intern self.send setter, val if respond_to? setter end end |
Class Method Details
.auth ⇒ Object
42 43 44 |
# File 'lib/daylife/base.rb', line 42 def self.auth @@auth end |
.get(method, parameters = {}) ⇒ Object
Make a get request to the input method with a parameters hash. Returbs an instanceor list of instances of API objects.
Article.get :get_topics, :article_id => 03cV5zI2fk03s
Generates the request:
article_getTopics?accesskey=<accesskey>&signature=<signature>&article_id=03cV5zI2fk03s
54 55 56 57 58 |
# File 'lib/daylife/base.rb', line 54 def self.get(method, parameters={}) parameters = @@auth.merge(parameters) resp = Request.new(methodize(method)).get(parameters) resp.parse end |
.methodize(method) ⇒ Object
Creates a Daylife style method name from a symbol.
Article.methodize :get_topics #=> "article_getTopics"
62 63 64 |
# File 'lib/daylife/base.rb', line 62 def self.methodize(method) "#{name.split('::').last.downcase}_#{method.to_s.gsub(/_([a-z])/) { $1.upcase }}" end |