Class: Amiando::Sync

Inherits:
Resource show all
Defined in:
lib/amiando/sync.rb

Overview

The main attributes are events and next_id.

Read through [Amiando::Sync::Event] to know how to understand the information returned.

Defined Under Namespace

Classes: Event

Instance Attribute Summary collapse

Attributes inherited from Resource

#request, #response, #success

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, #extract_attributes_from, method_missing, #populate, #populate_create

Methods included from Attributes

#[], #id, included, #method_missing, #respond_to?, #type

Methods included from Autorun

included

Constructor Details

#initialize(events, next_id) ⇒ Sync

Returns a new instance of Sync.



11
12
13
# File 'lib/amiando/sync.rb', line 11

def initialize(events, next_id)
  @events, @next_id = events, next_id
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Amiando::Attributes

Instance Attribute Details

#eventsObject

Returns the value of attribute events.



9
10
11
# File 'lib/amiando/sync.rb', line 9

def events
  @events
end

#next_idObject

Returns the value of attribute next_id.



9
10
11
# File 'lib/amiando/sync.rb', line 9

def next_id
  @next_id
end

Class Method Details

.find(last_id) ⇒ Amiando::Sync

Get the latest ‘synchronization’ events. Let’s not forget that in this case an ‘event’ is something that happened. It could be, for instance, that a new ticket was bought, that an event was modified, or similar.

Read the developers.amiando.com/index.php/REST_API_DataSync docs to find out how it really works. Simplifying, you find by the latest id you have, and go through the events returned.

When you find a data synchronization you get everything that happened (events) and the next id you should query for. Next time you should use that id when calling this method.

Parameters:

  • last_id

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/amiando/sync.rb', line 32

def self.find(last_id)
  object = Result.new do |response_body, result|
    if response_body["success"]
      events = response_body['events'].map do |event|
        Sync::Event.new(event)
      end
      Sync.new(events, response_body['nextId'])
    else
      result.errors = response_body['errors']
      false
    end
  end

  get object, "api/sync/#{last_id}"

  object
end