Class: TeamboxThingsSync::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/teambox-things-sync/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



6
7
8
9
10
11
# File 'lib/teambox-things-sync/base.rb', line 6

def initialize
  parse_config_file
  httpauth = Teambox::HTTPAuth.new(@config['username'], @config['password'],
                                   :api_endpoint => api_url(@config['teambox_url']))
  @client = Teambox::Base.new(httpauth)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/teambox-things-sync/base.rb', line 4

def config
  @config
end

Class Method Details

.find_or_create_project_in_things(project_name) ⇒ Object



36
37
38
# File 'lib/teambox-things-sync/base.rb', line 36

def self.find_or_create_project_in_things(project_name)
  Things::Project.find(project_name) or Things::Project.create(:name => project_name)
end

.find_or_create_todo_in_things(todo_name) ⇒ Object



40
41
42
# File 'lib/teambox-things-sync/base.rb', line 40

def self.find_or_create_todo_in_things(todo_name)
  Things::Todo.find(todo_name) or Things::Todo.create(:name => todo_name)
end

Instance Method Details

#api_url(url) ⇒ Object



49
50
51
# File 'lib/teambox-things-sync/base.rb', line 49

def api_url(url)
  url.gsub("http://", "")
end

#is_task_open?(status) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/teambox-things-sync/base.rb', line 53

def is_task_open?(status)
  [0,1].include? status
end

#synchroniseObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/teambox-things-sync/base.rb', line 13

def synchronise
  Timeout::timeout(@config['timeout_limit']) {
    begin
      projects = @client.projects
    rescue
      abort "Cannot fetch project list, check your internet connection."
    end

    projects.each do |project|
      log "Started working with #{project.name}"
      begin
        mark_as_done_at_remote(project)

        person_id = find_person_id(project.permalink)
        fetch_tasks_from_remote(project, person_id)
      rescue
        abort "Something went wrong while updating.\n" + $!
      end
    end
  }
end

#task_url(project_permalink, task_list_id, task_id) ⇒ Object



44
45
46
47
# File 'lib/teambox-things-sync/base.rb', line 44

def task_url(project_permalink, task_list_id, task_id)
  "#{@config['teambox_url']}/projects/#{project_permalink}/"+
    "task_lists/#{task_list_id}/tasks/#{task_id}"
end