idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
7,400
def build_request_chain ( sequence , context ) sequence . reverse . reduce ( nil ) do | successor , item | item . build_middleware ( context , successor ) end end
Given a middleware sequence filter out items not applicable to the current request and set up a chain of instantiated middleware objects ready to serve a request .
7,401
def dedup_sequence ( sequence ) sequence . uniq { | item | [ item . class , item . middleware , item . config ] } end
Remove middleware that have been included multiple times with the same config leaving only the first instance
7,402
def action_traits ( list_of_actions ) * list_of_actions , traits = list_of_actions if list_of_actions . last . is_a? ( Hash ) list_of_actions . reduce ( traits || { } ) do | memo , action | trait = ACTION_TRAITS . fetch ( action ) do raise Errors :: RouterUnknownDefaultAction , action end memo . merge ( action => trait...
Receives an array of symbols that represent actions for which the default traits should be used and then lastly an optional trait configuration .
7,403
def provide ( args ) args . each do | name , value | unless self . class . provides? ( name ) raise NameError , "#{self.class} does not provide #{name}" end @_context [ name ] = value end end
Make values available to middleware further down the stack . Accepts a hash of name = > value pairs . Names must have been declared by calling provides on the class .
7,404
def instrument proc do publish_start if ActiveSupport :: Notifications . notifier . listening? ( "coach.middleware.finish" ) instrument_deprecated { call } else ActiveSupport :: Notifications . instrument ( "finish_middleware.coach" , middleware_event ) { call } end end end
Use ActiveSupport to instrument the execution of the subsequent chain .
7,405
def validated_provides! if missing_requirements . any? raise Coach :: Errors :: MiddlewareDependencyNotMet . new ( @middleware , @previous_middlewares , missing_requirements ) end @middleware . provided + provided_by_chain end
Aggregates provided keys from the given middleware and all the middleware it uses . Can raise at any level assuming a used middleware is missing a required dependency .
7,406
def stats { endpoint_name : @endpoint_name , started_at : @start , duration : format_ms ( @duration ) , chain : sorted_chain . map do | event | { name : event [ :name ] , duration : format_ms ( event [ :duration ] ) } end , } end
Serialize the results of the benchmarking
7,407
def broadcast ( event , benchmark ) serialized = RequestSerializer . new ( event [ :request ] ) . serialize . merge ( benchmark . stats ) . merge ( event . slice ( :response , :metadata ) ) if ActiveSupport :: Notifications . notifier . listening? ( "coach.request" ) ActiveSupport :: Deprecation . warn ( "The 'coach.re...
Receives a handler . finish event with processed benchmark . Publishes to request . coach notification .
7,408
def targeting_criteria ( id = nil , opts = { } ) id ? TargetingCriteria . load ( account , id , opts ) : TargetingCriteria . all ( account , @id , opts ) end
Returns a collection of targeting criteria available to the current line item .
7,409
def each ( offset = 0 ) return to_enum ( :each , offset ) unless block_given? @collection [ offset .. - 1 ] . each { | element | yield ( element ) } unless exhausted? offset = [ @collection . size , offset ] . max fetch_next each ( offset , & Proc . new ) end self end
Method to iterate through all items until the Cursor is exhausted .
7,410
def filter ( * line_items ) result = { } params = { line_item_ids : line_items . join ( ',' ) , with_deleted : true } @account . line_items ( nil , params ) . each do | line_item | objective = line_item . objective . downcase . to_sym metrics = OBJECTIVES [ objective ] . map { | family | METRIC_FAMILIES [ family ] } . ...
Sets up the object with the correct account and client information .
7,411
def features validate_loaded resource = FEATURES % { id : @id } response = Request . new ( client , :get , resource ) . perform response . body [ :data ] end
Returns a collection of features available to the current account .
7,412
def scoped_timeline ( ids , opts = { } ) ids = ids . join ( ',' ) if ids . is_a? ( Array ) params = { user_ids : ids } . merge! ( opts ) resource = SCOPED_TIMELINE % { id : @id } request = Request . new ( client , :get , resource , params : params ) response = request . perform response . body [ :data ] end
Returns the most recent promotable Tweets created by one or more specified Twitter users .
7,413
def save if @id resource = self . class :: RESOURCE % { account_id : account . id , id : id } response = Request . new ( account . client , :put , resource , params : to_params ) . perform else resource = self . class :: RESOURCE_COLLECTION % { account_id : account . id } response = Request . new ( account . client , :...
Saves or updates the current object instance depending on the presence of object . id .
7,414
def delete! resource = self . class :: RESOURCE % { account_id : account . id , id : id } response = Request . new ( account . client , :delete , resource ) . perform from_response ( response . body [ :data ] ) end
Deletes the current object instance depending on the presence of object . id .
7,415
def perform if @file_size < SINGLE_UPLOAD_MAX resource = "#{DEFAULT_RESOURCE}#{@bucket}" response = upload ( resource , File . read ( @file_path ) ) response . headers [ 'location' ] [ 0 ] else response = init_chunked_upload bytes_per_chunk_size = response . headers [ 'x-ton-min-chunk-size' ] [ 0 ] . to_i location = re...
Creates a new TONUpload object instance .
7,416
def upload ( resource , bytes ) headers = { 'x-ton-expires' => DEFAULT_EXPIRE , 'content-length' => @file_size , 'content-type' => content_type } TwitterAds :: Request . new ( @client , :post , resource , domain : DEFAULT_DOMAIN , headers : headers , body : bytes ) . perform end
performs a single chunk upload
7,417
def init_chunked_upload headers = { 'x-ton-content-type' => content_type , 'x-ton-content-length' => @file_size , 'x-ton-expires' => DEFAULT_EXPIRE , 'content-length' => 0 , 'content-type' => content_type } resource = "#{DEFAULT_RESOURCE}#{@bucket}?resumable=true" TwitterAds :: Request . new ( @client , :post , resourc...
initialization for a multi - chunk upload
7,418
def upload_chunk ( resource , bytes , bytes_start , bytes_read ) headers = { 'content-type' => content_type , 'content-length' => bytes . size , 'content-range' => "bytes #{bytes_start}-#{bytes_read - 1}/#{@file_size}" } response = TwitterAds :: Request . new ( @client , :put , resource , domain : DEFAULT_DOMAIN , head...
uploads a single chunk of a multi - chunk upload
7,419
def update ( file_path , list_type , operation = 'ADD' ) upload = TwitterAds :: TONUpload . new ( account . client , file_path ) update_audience ( self , upload . perform , list_type , operation ) reload! end
Updates the current tailored audience instance .
7,420
def status return nil unless id resource = RESOURCE_UPDATE % { account_id : account . id } request = Request . new ( account . client , :get , resource , params : to_params ) Cursor . new ( nil , request ) . to_a . select { | change | change [ :tailored_audience_id ] == id } end
Returns the status of all changes for the current tailored audience instance .
7,421
def users ( params ) resource = RESOURCE_USERS % { account_id : account . id , id : id } headers = { 'Content-Type' => 'application/json' } response = TwitterAds :: Request . new ( account . client , :post , resource , headers : headers , body : params . to_json ) . perform success_count = response . body [ :data ] [ :...
This is a private API and requires whitelisting from Twitter .
7,422
def accounts ( id = nil , opts = { } ) id ? Account . load ( self , id ) : Account . all ( self , opts ) end
Returns a collection of advertiser Accounts available to the current access token .
7,423
def evaluate ( relation , param ) if splat_param? relation . send ( name , * format_param ( param ) ) else relation . send ( name , format_param ( param ) ) end end
Evaluate the method in the context of the supplied relation and parameter
7,424
def fill_in ( field_locator , options = { } ) field = locate_field ( field_locator , TextField , TextareaField , PasswordField ) field . raise_error_if_disabled field . set ( options [ :with ] ) end
Verifies an input field or textarea exists on the current page and stores a value for it which will be sent when the form is submitted .
7,425
def assert_contain ( content ) hc = HasContent . new ( content ) assert hc . matches? ( current_dom ) , hc . failure_message end
Asserts that the body of the response contain the supplied string or regexp
7,426
def normalize_url ( href ) uri = URI . parse ( href ) normalized_url = [ ] normalized_url << "#{uri.scheme}://" if uri . scheme normalized_url << uri . host if uri . host normalized_url << ":#{uri.port}" if uri . port && ! [ 80 , 443 ] . include? ( uri . port ) normalized_url << uri . path if uri . path normalized_url ...
remove protocol host and anchor
7,427
def params query_string = [ ] replaces = { } fields . each do | field | next if field . to_query_string . nil? replaces . merge! ( { field . digest_value => field . test_uploaded_file } ) if field . is_a? ( FileField ) query_string << field . to_query_string end query_params = self . class . query_string_to_params ( qu...
iterate over all form fields to build a request querystring to get params from it for file_field we made a work around to pass a digest as value to later replace it in params hash with the real file .
7,428
def assert_have_selector ( name , attributes = { } , & block ) matcher = HaveSelector . new ( name , attributes , & block ) assert matcher . matches? ( response_body ) , matcher . failure_message end
Asserts that the body of the response contains the supplied selector
7,429
def prompt_for_permission UI . titled_section 'Running Pre-Install Commands' do commands = pre_install_commands . length > 1 ? 'commands' : 'command' UI . puts "In order to try this pod, CocoaPods-Try needs to run the following #{commands}:" pre_install_commands . each { | command | UI . puts " - #{command}" } UI . put...
If we need to run commands from pod - try we should let the users know what is going to be running on their device .
7,430
def run_pre_install_commands ( prompt ) if pre_install_commands prompt_for_permission if prompt pre_install_commands . each { | command | Executable . execute_command ( 'bash' , [ '-ec' , command ] , true ) } end end
Runs the pre_install_commands from
7,431
def level = ( new_level ) if new_level . respond_to? ( :to_int ) new_level = STD_LOGGER_LEVELS [ new_level ] end LogbackUtil . set_log_level ( @logger , new_level ) end
Sets current logger s level
7,432
def start @java_daemon . set_action do action end @java_daemon . set_error_callback do | _ , err | on_error ( err ) end @java_daemon . set_stop_callback do | _ | on_stop end @java_daemon . start self end
Creates a daemon object .
7,433
def load ( string ) marshal , compress , value = decompose ( string ) marshal . load ( inflate ( value , compress ) ) rescue TypeError , NoMethodError string end
Parse a dumped value using the embedded options .
7,434
def decompose ( string ) flags = string [ 0 ] . unpack ( 'C' ) . first if flags < 16 marshal = serializers . rassoc ( flags ) compress = ( flags & COMPRESSED_FLAG ) != 0 [ marshal , compress , string [ 1 .. - 1 ] ] else [ @options [ :marshal ] , @options [ :compress ] , string ] end end
Decompose an option embedded string into marshal compression and value .
7,435
def write ( key , value , options = { } ) options = merged_options ( options ) invoke ( :write , key ) do | store | write_entity ( key , value , store , options ) end end
Writes data to the cache using the given key . Will overwrite whatever value is already stored at that key .
7,436
def delete ( key , options = { } ) namespaced = namespaced_key ( key , merged_options ( options ) ) invoke ( :delete , key ) do | store | store . del ( namespaced ) > 0 end end
Delete the value stored at the specified key . Returns true if anything was deleted false otherwise .
7,437
def fetch ( key , options = { } ) options ||= { } value = read ( key , options ) unless options [ :force ] if value . nil? && block_given? value = yield ( key ) write ( key , value , options ) end value end
Fetches data from the cache using the given key . If there is data in the cache with the given key then that data is returned .
7,438
def increment ( key , amount = 1 , options = { } ) invoke ( :increment , key ) do | store | alter ( store , key , amount , options ) end end
Increment a key in the store .
7,439
def decrement ( key , amount = 1 , options = { } ) invoke ( :decrement , key ) do | store | alter ( store , key , - amount , options ) end end
Decrement a key in the store .
7,440
def read_multi ( * keys ) options = merged_options ( extract_options! ( keys ) ) mapping = keys . map { | key | namespaced_key ( key , options ) } return { } if keys . empty? invoke ( :read_multi , keys ) do | store | values = store . mget ( * mapping ) . map { | value | entity . load ( value ) } refresh_entity ( mappi...
Efficiently read multiple values at once from the cache . Options can be passed in the last argument .
7,441
def write_multi ( hash , options = { } ) options = merged_options ( options ) invoke ( :write_multi , hash . keys ) do | store | store . multi do hash . each { | key , value | write_entity ( key , value , store , options ) } end end end
Write multiple key value pairs simultaneously . This is an atomic operation that will always succeed and will overwrite existing values .
7,442
def fetch_multi ( * keys ) options = extract_options! ( keys ) . merge ( retain_nils : true ) results = read_multi ( * keys , options ) missing = { } invoke ( :fetch_multi , keys ) do | _store | results . each do | key , value | next unless value . nil? value = yield ( key ) missing [ key ] = value results [ key ] = va...
Fetches multiple keys from the cache using a single call to the server and filling in any cache misses . All read and write operations are executed atomically .
7,443
def exist? ( key , options = { } ) invoke ( :exist? , key ) do | store | store . exists ( namespaced_key ( key , merged_options ( options ) ) ) end end
Returns true if the cache contains an entry for the given key .
7,444
def clear ( options = { } ) invoke ( :clear , '*' ) do | store | if options [ :async ] store . flushdb ( async : true ) else store . flushdb end end end
Clear the entire cache by flushing the current database .
7,445
def fields_for ( * args , & block ) if search_obj = args . find { | arg | arg . is_a? ( Searchlogic :: Search ) } args . unshift ( :search ) if args . first == search_obj options = args . extract_options! if ! options [ :skip_order_field ] concat ( content_tag ( "div" , hidden_field_tag ( "#{args.first}[order]" , searc...
Automatically adds an order hidden field in your form to preserve how the data is being ordered .
7,446
def load_case_rules! ( rules ) [ :lastname , :firstname , :middlename ] . each do | name_part | [ :exceptions , :suffixes ] . each do | section | entries = rules [ name_part . to_s ] [ section . to_s ] next if entries . nil? entries . each do | entry | load_case_entry ( name_part , section , entry ) end end end end
Load rules for names
7,447
def load_gender_rules! ( rules ) [ :lastname , :firstname , :middlename ] . each do | name_part | Petrovich :: GENDERS . each do | section | entries = rules [ 'gender' ] [ name_part . to_s ] [ 'suffixes' ] [ section . to_s ] Array ( entries ) . each do | entry | load_gender_entry ( name_part , section , entry ) end exc...
Load rules for genders
7,448
def difference ( other ) require 'pact/matchers' Pact :: Matchers . diff ( query , symbolize_keys ( CGI :: parse ( other . query ) ) , allow_unexpected_keys : false ) end
other will always be a QueryString not a QueryHash as it will have ben created from the actual query string .
7,449
def html_safe_strings ( obj ) if obj . is_a? ( String ) obj . html_safe elsif obj . is_a? ( Hash ) obj . each do | key , value | obj [ key ] = html_safe_strings ( value ) end elsif obj . is_a? ( Array ) obj . map! { | e | html_safe_strings ( e ) } else obj end end
Iterate through data object and recursively mark any found string as html_safe
7,450
def opts name , & b fail "command name must be a symbol" unless name . is_a? Symbol if name . to_s =~ / / fail "Camel-casing is not allowed (#{name})" end parser = OptionParser . new name . to_s , @ns . shell . fs , & b summary = parser . summary? parser . specs . each do | opt_name , spec | if opt_name . to_s =~ / / f...
Command definition functions
7,451
def get_activities ( params = { } ) if params [ :foreign_id_times ] foreign_ids = [ ] timestamps = [ ] params [ :foreign_id_times ] . each { | e | foreign_ids << e [ :foreign_id ] timestamps << e [ :time ] } params = { foreign_ids : foreign_ids , timestamps : timestamps , } end signature = Stream :: Signer . create_jwt...
Get activities directly via ID or Foreign ID + timestamp
7,452
def traverse base , arcs objs = [ base ] arcs . each_with_index do | arc , i | objs . map! { | obj | traverse_one obj , arc , i == 0 } objs . flatten! end objs end
Starting from base traverse each path element in arcs . Since the path may contain wildcards this function returns a list of matches .
7,453
def follow_many ( follows , activity_copy_limit = nil ) query_params = { } unless activity_copy_limit . nil? query_params [ 'activity_copy_limit' ] = activity_copy_limit end signature = Stream :: Signer . create_jwt_token ( 'follower' , '*' , @api_secret , '*' ) make_request ( :post , '/follow_many/' , signature , quer...
Follows many feeds in one single request
7,454
def add_to_many ( activity_data , feeds ) data = { :feeds => feeds , :activity => activity_data } signature = Stream :: Signer . create_jwt_token ( 'feed' , '*' , @api_secret , '*' ) make_request ( :post , '/feed/add_to_many/' , signature , { } , data ) end
Adds an activity to many feeds in one single request
7,455
def close_script_style tag = @tag_stack . last if @already =~ / \] \] / new_already = script_style_cdata_start ( tag ) new_already << "\n" unless @already . start_with? ( "\n" ) new_already << @already new_already << "\n" unless @already . end_with? ( "\n" ) new_already << script_style_cdata_end ( tag ) @already = new_...
Finish script or style tag content wrapping it in CDATA if necessary and add it to our original
7,456
def maruku_error ( s , src = nil , con = nil , recover = nil ) policy = get_setting ( :on_error ) case policy when :ignore when :raise raise_error create_frame ( describe_error ( s , src , con , recover ) ) when :warning tell_user create_frame ( describe_error ( s , src , con , recover ) ) else raise "Unknown on_error ...
Properly handles a formatting error . All such errors go through this method .
7,457
def spaces_before_first_char ( s ) s = MaRuKu :: MDLine . new ( s . gsub ( / \t \t / ) { $1 + " " * ( TAB_SIZE - $1 . length % TAB_SIZE ) } ) match = case s . md_type when :ulist s [ / \s \* \+ \- \s \{ \. \} \s / ] when :olist s [ / \s \d \. \s \{ \. \} \s / ] else tell_user "BUG (my bad): '#{s}' is not a list" '' end...
This returns the position of the first non - list character in a list item .
7,458
def t2_parse_blocks ( src , output ) while src . cur_line l = src . shift_line if l . t2_empty? then src . shift_line next end signature , l = if l . t2_contains_signature? l . t2_get_signature else [ Textile2Signature . new , l ] end if handling = T2_Handling . has_key? ( signature . block_name ) if self . responds_to...
Input is a LineSource
7,459
def to_html output_options = Nokogiri :: XML :: Node :: SaveOptions :: DEFAULT_XHTML ^ Nokogiri :: XML :: Node :: SaveOptions :: FORMAT @fragment . children . inject ( "" ) do | out , child | out << child . serialize ( :save_with => output_options , :encoding => 'UTF-8' ) end end
Convert this fragment to an HTML or XHTML string .
7,460
def span_descendents ( e ) ns = Nokogiri :: XML :: NodeSet . new ( Nokogiri :: XML :: Document . new ) e . element_children . inject ( ns ) do | descendents , c | if HTML_INLINE_ELEMS . include? ( c . name ) descendents << c descendents += span_descendents ( c ) end descendents end end
Get all span - level descendents of the given element recursively as a flat NodeSet .
7,461
def span_descendents ( e ) descendents = [ ] e . each_element do | c | name = c . respond_to? ( :name ) ? c . name : nil if name && HTML_INLINE_ELEMS . include? ( c . name ) descendents << c descendents += span_descendents ( c ) end end end
Get all span - level descendents of the given element recursively as an Array .
7,462
def track! ( & block ) if block_given? start_at = Time . now block . call end_at = Time . now self . options . time = ( end_at - start_at ) . to_i * 1000 end super end
tracks the timing hit type
7,463
def params { } . merge! ( base_params ) . merge! ( tracker_default_params ) . merge! ( global_options_params ) . merge! ( hit_params ) . merge! ( custom_dimensions ) . merge! ( custom_metrics ) . merge! ( measurement_params ) . reject { | _ , v | v . nil? } end
collects the parameters from options for this hit type
7,464
def add_measurement ( key , options = { } ) if options . is_a? ( Hash ) self . measurements << Measurement . lookup ( key ) . new ( options ) else self . measurements << options end end
Add a measurement by its symbol name with options
7,465
def params { } . merge! ( measurable_params ) . merge! ( custom_dimensions ) . merge! ( custom_metrics ) . reject { | _ , v | v . nil? } end
collects the parameters from options for this measurement
7,466
def clean! files_to_keep = cache . keys . concat ( cache . values ) if ( sprockets_manifest = Dir . entries ( "#{base_dir}" ) . detect { | entry | entry =~ SPROCKETS_MANIFEST_REGEX } ) files_to_keep . concat ( JSON . parse ( File . read ( "#{base_dir}/#{sprockets_manifest}" ) ) . fetch ( "files" , { } ) . keys ) end Di...
Remove any files not directly referenced by the manifest .
7,467
def nuke! Dir [ "#{base_dir}/**/*" ] . select { | path | path =~ FINGERPRINT_REGEX } . each { | file | FileUtils . rm ( file ) } FileUtils . rm ( manifest_path ) end
Remove manifest any fingerprinted files .
7,468
def valid? @errors = [ ] if ! line_item_id . nil? && line_item_id !~ GUID_REGEX @errors << [ 'line_item_id' , 'must be blank or a valid Xero GUID' ] end unless description @errors << [ 'description' , "can't be blank" ] end if tax_type && ! TAX_TYPE [ tax_type ] @errors << [ 'tax_type' , "must be one of #{TAX_TYPE.keys...
Validate the LineItem record according to what will be valid by the gateway .
7,469
def find_all_by_type ( account_type ) raise AccountsListNotLoadedError unless loaded? @accounts . inject ( [ ] ) do | list , account | list << account if account . type == account_type list end end
Return a list of all accounts matching account_type .
7,470
def find_all_by_tax_type ( tax_type ) raise AccountsListNotLoadedError unless loaded? @accounts . inject ( [ ] ) do | list , account | list << account if account . tax_type == tax_type list end end
Return a list of all accounts matching tax_type .
7,471
def valid? @errors = [ ] if ! contact_id . nil? && contact_id !~ GUID_REGEX @errors << [ 'contact_id' , 'must be blank or a valid Xero GUID' ] end if status && ! CONTACT_STATUS [ status ] @errors << [ 'status' , "must be one of #{CONTACT_STATUS.keys.join('/')}" ] end unless name @errors << [ 'name' , "can't be blank" ]...
Validate the Contact record according to what will be valid by the gateway .
7,472
def get_contacts ( options = { } ) request_params = { } if ! options [ :updated_after ] . nil? warn '[warning] :updated_after is depracated in XeroGateway#get_contacts. Use :modified_since' options [ :modified_since ] = options . delete ( :updated_after ) end request_params [ :ContactID ] = options [ :contact_id ] if ...
The consumer key and secret here correspond to those provided to you by Xero inside the API Previewer .
7,473
def build_contact ( contact = { } ) case contact when Contact then contact . gateway = self when Hash then contact = Contact . new ( contact . merge ( { :gateway => self } ) ) end contact end
Factory method for building new Contact objects associated with this gateway .
7,474
def update_contact ( contact ) raise "contact_id or contact_number is required for updating contacts" if contact . contact_id . nil? and contact . contact_number . nil? save_contact ( contact ) end
Updates an existing Xero contact
7,475
def update_contacts ( contacts ) b = Builder :: XmlMarkup . new request_xml = b . Contacts { contacts . each do | contact | contact . to_xml ( b ) end } response_xml = http_post ( @client , "#{@xero_url}/Contacts" , request_xml , { } ) response = parse_response ( response_xml , { :request_xml => request_xml } , { :requ...
Updates an array of contacts in a single API operation .
7,476
def get_contact_groups ( options = { } ) request_params = { } request_params [ :ContactGroupID ] = options [ :contact_group_id ] if options [ :contact_group_id ] request_params [ :order ] = options [ :order ] if options [ :order ] request_params [ :where ] = options [ :where ] if options [ :where ] response_xml = http_...
Retreives all contact groups from Xero
7,477
def get_contact_group_by_id ( contact_group_id ) request_params = { :ContactGroupID => contact_group_id } response_xml = http_get ( @client , "#{@xero_url}/ContactGroups/#{CGI.escape(contact_group_id)}" , request_params ) parse_response ( response_xml , { :request_params => request_params } , { :request_signature => 'G...
Retreives a contact group by its id .
7,478
def get_invoices ( options = { } ) request_params = { } request_params [ :InvoiceID ] = options [ :invoice_id ] if options [ :invoice_id ] request_params [ :InvoiceNumber ] = options [ :invoice_number ] if options [ :invoice_number ] request_params [ :order ] = options [ :order ] if options [ :order ] request_params [ ...
Retrieves all invoices from Xero
7,479
def get_invoice ( invoice_id_or_number , format = :xml ) request_params = { } headers = { } headers . merge! ( "Accept" => "application/pdf" ) if format == :pdf url = "#{@xero_url}/Invoices/#{CGI.escape(invoice_id_or_number)}" response = http_get ( @client , url , request_params , headers ) if format == :pdf Tempfile ....
Retrieves a single invoice
7,480
def build_invoice ( invoice = { } ) case invoice when Invoice then invoice . gateway = self when Hash then invoice = Invoice . new ( invoice . merge ( :gateway => self ) ) end invoice end
Factory method for building new Invoice objects associated with this gateway .
7,481
def create_invoices ( invoices ) b = Builder :: XmlMarkup . new request_xml = b . Invoices { invoices . each do | invoice | invoice . to_xml ( b ) end } response_xml = http_put ( @client , "#{@xero_url}/Invoices?SummarizeErrors=false" , request_xml , { } ) response = parse_response ( response_xml , { :request_xml => re...
Creates an array of invoices with a single API request .
7,482
def get_credit_notes ( options = { } ) request_params = { } request_params [ :CreditNoteID ] = options [ :credit_note_id ] if options [ :credit_note_id ] request_params [ :CreditNoteNumber ] = options [ :credit_note_number ] if options [ :credit_note_number ] request_params [ :order ] = options [ :order ] if options [ ...
Retrieves all credit_notes from Xero
7,483
def get_credit_note ( credit_note_id_or_number ) request_params = { } url = "#{@xero_url}/CreditNotes/#{CGI.escape(credit_note_id_or_number)}" response_xml = http_get ( @client , url , request_params ) parse_response ( response_xml , { :request_params => request_params } , { :request_signature => 'GET/CreditNote' } ) e...
Retrieves a single credit_note
7,484
def build_credit_note ( credit_note = { } ) case credit_note when CreditNote then credit_note . gateway = self when Hash then credit_note = CreditNote . new ( credit_note . merge ( :gateway => self ) ) end credit_note end
Factory method for building new CreditNote objects associated with this gateway .
7,485
def create_credit_note ( credit_note ) request_xml = credit_note . to_xml response_xml = http_put ( @client , "#{@xero_url}/CreditNotes" , request_xml ) response = parse_response ( response_xml , { :request_xml => request_xml } , { :request_signature => 'PUT/credit_note' } ) response . response_item = response . credit...
Creates an credit_note in Xero based on an credit_note object .
7,486
def create_credit_notes ( credit_notes ) b = Builder :: XmlMarkup . new request_xml = b . CreditNotes { credit_notes . each do | credit_note | credit_note . to_xml ( b ) end } response_xml = http_put ( @client , "#{@xero_url}/CreditNotes" , request_xml , { } ) response = parse_response ( response_xml , { :request_xml =...
Creates an array of credit_notes with a single API request .
7,487
def get_bank_transactions ( options = { } ) request_params = { } request_params [ :BankTransactionID ] = options [ :bank_transaction_id ] if options [ :bank_transaction_id ] request_params [ :ModifiedAfter ] = options [ :modified_since ] if options [ :modified_since ] request_params [ :order ] = options [ :order ] if o...
Retrieves all bank transactions from Xero
7,488
def get_bank_transaction ( bank_transaction_id ) request_params = { } url = "#{@xero_url}/BankTransactions/#{CGI.escape(bank_transaction_id)}" response_xml = http_get ( @client , url , request_params ) parse_response ( response_xml , { :request_params => request_params } , { :request_signature => 'GET/BankTransaction' ...
Retrieves a single bank transaction
7,489
def get_manual_journals ( options = { } ) request_params = { } request_params [ :ManualJournalID ] = options [ :manual_journal_id ] if options [ :manual_journal_id ] request_params [ :ModifiedAfter ] = options [ :modified_since ] if options [ :modified_since ] response_xml = http_get ( @client , "#{@xero_url}/ManualJou...
Retrieves all manual journals from Xero
7,490
def get_manual_journal ( manual_journal_id ) request_params = { } url = "#{@xero_url}/ManualJournals/#{CGI.escape(manual_journal_id)}" response_xml = http_get ( @client , url , request_params ) parse_response ( response_xml , { :request_params => request_params } , { :request_signature => 'GET/ManualJournal' } ) end
Retrieves a single manual journal
7,491
def create_payment ( payment ) b = Builder :: XmlMarkup . new request_xml = b . Payments do payment . to_xml ( b ) end response_xml = http_put ( @client , "#{xero_url}/Payments" , request_xml ) parse_response ( response_xml , { :request_xml => request_xml } , { :request_signature => 'PUT/payments' } ) end
Create Payment record in Xero
7,492
def get_payments ( options = { } ) request_params = { } request_params [ :PaymentID ] = options [ :payment_id ] if options [ :payment_id ] request_params [ :ModifiedAfter ] = options [ :modified_since ] if options [ :modified_since ] request_params [ :order ] = options [ :order ] if options [ :order ] request_params [ ...
Gets all Payments for a specific organisation in Xero
7,493
def get_payment ( payment_id , options = { } ) request_params = { } response_xml = http_get ( client , "#{@xero_url}/Payments/#{payment_id}" , request_params ) parse_response ( response_xml , { :request_params => request_params } , { :request_signature => 'GET/payments' } ) end
Gets a single Payment for a specific organsation in Xero
7,494
def get_payroll_calendars ( options = { } ) request_params = { } response_xml = http_get ( client , "#{@payroll_url}/PayrollCalendars" , request_params ) parse_response ( response_xml , { :request_params => request_params } , { :request_signature => 'GET/payroll_calendars' } ) end
Get the Payroll calendars for a specific organization in Xero
7,495
def get_pay_runs ( options = { } ) request_params = { } response_xml = http_get ( client , "#{@payroll_url}/PayRuns" , request_params ) parse_response ( response_xml , { :request_params => request_params } , { :request_signature => 'GET/pay_runs' } ) end
Get the Pay Runs for a specific organization in Xero
7,496
def get_report ( id_or_name , options = { } ) request_params = options . inject ( { } ) do | params , ( key , val ) | xero_key = key . to_s . camelize . gsub ( / /i , "ID" ) . to_sym params [ xero_key ] = val params end response_xml = http_get ( @client , "#{@xero_url}/reports/#{id_or_name}" , request_params ) parse_re...
Retrieves reports from Xero
7,497
def save_contact ( contact ) request_xml = contact . to_xml response_xml = nil create_or_save = nil if contact . contact_id . nil? && contact . contact_number . nil? response_xml = http_put ( @client , "#{@xero_url}/Contacts" , request_xml , { } ) create_or_save = :create else response_xml = http_post ( @client , "#{@x...
Create or update a contact record based on if it has a contact_id or contact_number .
7,498
def save_invoice ( invoice ) request_xml = invoice . to_xml response_xml = nil create_or_save = nil if invoice . invoice_id . nil? response_xml = http_put ( @client , "#{@xero_url}/Invoices" , request_xml , { } ) create_or_save = :create else response_xml = http_post ( @client , "#{@xero_url}/Invoices" , request_xml , ...
Create or update an invoice record based on if it has an invoice_id .
7,499
def save_bank_transaction ( bank_transaction ) request_xml = bank_transaction . to_xml response_xml = nil create_or_save = nil if bank_transaction . bank_transaction_id . nil? response_xml = http_put ( @client , "#{@xero_url}/BankTransactions" , request_xml , { } ) create_or_save = :create else response_xml = http_post...
Create or update a bank transaction record based on if it has an bank_transaction_id .