Class: Postly::Connection
- Inherits:
-
Object
- Object
- Postly::Connection
- Includes:
- HTTParty
- Defined in:
- lib/postly/connection.rb
Class Method Summary collapse
- .array_or_hash(response) ⇒ Object
-
.class_name ⇒ Object
Split off the Namespace.
-
.conform(response) ⇒ Object
quack! quack!.
- .defaults ⇒ Object
- .many(collection_name) ⇒ Object
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Connection
constructor
A new instance of Connection.
- #singularized_class_name(collection_name) ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Connection
Returns a new instance of Connection.
8 9 10 |
# File 'lib/postly/connection.rb', line 8 def initialize attrs={} attrs.each_pair {|k,v| send("#{k}=".to_sym, v) if respond_to? "#{k}=".to_sym } end |
Class Method Details
.array_or_hash(response) ⇒ Object
28 29 30 |
# File 'lib/postly/connection.rb', line 28 def self.array_or_hash response response["rsp"][self.class_name.downcase] end |
.class_name ⇒ Object
Split off the Namespace
33 34 35 |
# File 'lib/postly/connection.rb', line 33 def self.class_name @class_name ||= self.to_s.split("::").last end |
.conform(response) ⇒ Object
quack! quack!
18 19 20 21 22 23 24 25 26 |
# File 'lib/postly/connection.rb', line 18 def self.conform response result = array_or_hash response case result when Hash self.new result when Array result.collect { |item| self.new item } end end |
Instance Method Details
#singularized_class_name(collection_name) ⇒ Object
44 45 46 |
# File 'lib/postly/connection.rb', line 44 def singularized_class_name collection_name collection_name.to_s.singularize.camelize.constantize end |