Class: Koala::Facebook::BatchOperation
- Inherits:
-
Object
- Object
- Koala::Facebook::BatchOperation
- Defined in:
- lib/koala/batch_operation.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#batch_api ⇒ Object
readonly
Returns the value of attribute batch_api.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#http_options ⇒ Object
readonly
Returns the value of attribute http_options.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#post_processing ⇒ Object
readonly
Returns the value of attribute post_processing.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ BatchOperation
constructor
A new instance of BatchOperation.
- #to_batch_params(main_access_token) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ BatchOperation
Returns a new instance of BatchOperation.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/koala/batch_operation.rb', line 12 def initialize( = {}) @identifier = self.class.next_identifier @args = ([:args] || {}).dup # because we modify it below @access_token = [:access_token] @http_options = ([:http_options] || {}).dup # dup because we modify it below @batch_args = @http_options.delete(:batch_args) || {} @url = [:url] @method = [:method].to_sym @post_processing = [:post_processing] process_binary_args raise Koala::KoalaError, "Batch operations require an access token, none provided." unless @access_token end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
4 5 6 |
# File 'lib/koala/batch_operation.rb', line 4 def access_token @access_token end |
#batch_api ⇒ Object (readonly)
Returns the value of attribute batch_api.
4 5 6 |
# File 'lib/koala/batch_operation.rb', line 4 def batch_api @batch_api end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
4 5 6 |
# File 'lib/koala/batch_operation.rb', line 4 def files @files end |
#http_options ⇒ Object (readonly)
Returns the value of attribute http_options.
4 5 6 |
# File 'lib/koala/batch_operation.rb', line 4 def @http_options end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
4 5 6 |
# File 'lib/koala/batch_operation.rb', line 4 def identifier @identifier end |
#post_processing ⇒ Object (readonly)
Returns the value of attribute post_processing.
4 5 6 |
# File 'lib/koala/batch_operation.rb', line 4 def post_processing @post_processing end |
Class Method Details
.next_identifier ⇒ Object
8 9 10 |
# File 'lib/koala/batch_operation.rb', line 8 def self.next_identifier @identifier += 1 end |
Instance Method Details
#to_batch_params(main_access_token) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/koala/batch_operation.rb', line 27 def to_batch_params(main_access_token) # set up the arguments args_string = Koala.http_service.encode_params(@access_token == main_access_token ? @args : @args.merge(:access_token => @access_token)) response = { :method => @method.to_s, :relative_url => @url, } # handle batch-level arguments, such as name, depends_on, and attached_files @batch_args[:attached_files] = @files.keys.join(",") if @files response.merge!(@batch_args) if @batch_args # for get and delete, we append args to the URL string # otherwise, they go in the body if args_string.length > 0 if args_in_url? response[:relative_url] += (@url =~ /\?/ ? "&" : "?") + args_string if args_string.length > 0 else response[:body] = args_string if args_string.length > 0 end end response end |