basecampx 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .rvmrc
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  The new Basecamp API Ruby wrapper.
4
4
  Currently support only rails, feel free to help me get rid of Rails dependency.
5
+ Based on [mattgaidica](https://github.com/mattgaidica) repo [basecamp-wrap](https://github.com/mattgaidica/basecamp-wrap)
5
6
 
6
7
  ## Installation
7
8
 
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
@@ -6,8 +6,8 @@ require 'basecampx/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "basecampx"
8
8
  gem.version = Basecampx::VERSION
9
- gem.authors = ["Anton Zaytsev"]
10
- gem.email = ["me@antonzaytsev.com"]
9
+ gem.authors = %w{"Anton Zaytsev"}
10
+ gem.email = %w{"me@antonzaytsev.com"}
11
11
  gem.description = %q{Basecamp new ruby api wrapper}
12
12
  gem.summary = %q{Provides simple methods to work with basecamp new api}
13
13
  gem.homepage = ""
@@ -4,5 +4,8 @@ require 'yaml'
4
4
 
5
5
  require "basecampx/version"
6
6
  require 'basecampx/base'
7
+ require 'basecampx/resource'
7
8
  require 'basecampx/resources/person'
9
+ require 'basecampx/resources/project'
8
10
  require 'basecampx/resources/todo'
11
+ require 'basecampx/resources/todo_list'
@@ -2,31 +2,21 @@ module Basecampx
2
2
  class << self
3
3
  def use! project=:default
4
4
  @project = project
5
- @details = YAML.load(File.read(File.join(Rails.root, 'config', 'basecampx.yaml')))
6
- @connect_details = @details[project.to_s]
7
- @account_endpoint = "https://basecamp.com/#{@connect_details['project_id']}/api/v#{@connect_details['api_version'] || 1}"
8
-
9
- test_connection
10
- end
11
-
12
- def test_connection
13
- true
5
+ details = YAML.load(File.read(File.join(Rails.root, 'config', 'basecampx.yaml')))
6
+ @connect_details = details[project.to_s]
14
7
  end
15
8
 
16
- def use_custom! username, password, project_id
17
-
9
+ def use_custom! username, password, project_id, api_version=1
10
+ @project = :custom
11
+ @connect_details = {
12
+ 'project_id' => project_id,
13
+ 'username' => username,
14
+ 'password' => password,
15
+ 'api_version' => api_version
16
+ }
18
17
  end
19
18
 
20
- #def initialize username='', password='', account_endpoint='https://basecamp.com/1908192/api/v1', app='Syllabuster Sync (http://sylly.co)'
21
- # @username = username
22
- # @password = password
23
- # @account_endpoint = account_endpoint
24
- # @app = app
25
- #end
26
-
27
19
  def params
28
- account_endpoint
29
-
30
20
  {
31
21
  :basic_auth => {
32
22
  :username => @connect_details['username'],
@@ -39,11 +29,11 @@ module Basecampx
39
29
  end
40
30
 
41
31
  def account_endpoint
42
- if !@account_endpoint
32
+ if @project.nil?
43
33
  self.use!
44
34
  end
45
35
 
46
- @account_endpoint
36
+ "https://basecamp.com/#{@connect_details['project_id']}/api/v#{@connect_details['api_version'] || 1}"
47
37
  end
48
38
 
49
39
  def handle response
@@ -63,31 +53,9 @@ module Basecampx
63
53
  handle response
64
54
  end
65
55
 
66
- def todolists project_id
67
- self.request "#{account_endpoint}/projects/#{project_id}/todolists.json"
68
- end
69
-
70
- def todolist project_id, todolist_id
71
- response = HTTParty.get "#{@account_endpoint}/projects/#{project_id}/todolists/#{todolist_id}.json", params
72
- handle response
73
- end
74
-
75
- def todos project_id, todo_id
76
- self.request "#{@account_endpoint}/projects/#{project_id}/todos/#{todo_id}.json"
77
- end
78
-
79
- def people
80
- json = self.request "#{account_endpoint}/people.json"
81
- self::Person.parse json
82
- end
83
-
84
- def person account_id
85
- json = self.request "#{@account_endpoint}/people/#{account_id}.json"
86
- self::Person.new json
87
- end
88
-
89
56
  def request url
90
- handle HTTParty.get url, params
57
+ handle HTTParty.get "#{account_endpoint}/#{url.sub(/^\//, '')}", params
91
58
  end
59
+
92
60
  end
93
61
  end
@@ -0,0 +1,33 @@
1
+ module Basecampx
2
+ class Resource
3
+ class << self
4
+ def parse json
5
+ output = []
6
+
7
+ json.each do |user|
8
+ output << self.new(user)
9
+ end
10
+
11
+ output
12
+ end
13
+ end
14
+
15
+ def initialize args=[]
16
+ self.update_details args
17
+ end
18
+
19
+ def update_details args
20
+ args.each do |key, value|
21
+ self.send(key.to_s+'=', value) if self.respond_to?((key.to_s+'=').to_s)
22
+ end
23
+ end
24
+
25
+ def save
26
+ # TODO: add ability to create/update/save/delete resources
27
+ end
28
+
29
+ def delete
30
+
31
+ end
32
+ end
33
+ end
@@ -1,35 +1,20 @@
1
1
  module Basecampx
2
- class Person
2
+ class Person < Basecampx::Resource
3
3
 
4
4
  attr_accessor :id, :name, :email_address, :admin, :created_at, :avatar_url, :url, :identity_id,
5
5
  :events, :assigned_todos, :todo_list
6
6
 
7
- def self.parse json
8
- output = []
9
-
10
- json.each do |user|
11
- output << self.new(user)
12
- end
13
-
14
- output
7
+ def self.find person_id
8
+ self.new Basecampx.request "people/#{person_id}.json"
15
9
  end
16
10
 
17
- def initialize args
18
- self.update_details args
19
- end
20
-
21
- def update_details args
22
- args.each do |key, value|
23
- self.send(key.to_s+'=', value) if self.respond_to?((key.to_s+'=').to_s)
24
- end
11
+ def self.all
12
+ self.parse Basecampx.request "people.json"
25
13
  end
26
14
 
15
+ # GET /people/1/assigned_todos.json
27
16
  def todos
28
- if self.assigned_todos.nil?
29
- self.details
30
- end
31
-
32
- self.todo_list = Basecampx.request self.assigned_todos['url']
17
+ TodoList.parse Basecampx.request "people/#{self.id}/assigned_todos.json"
33
18
  end
34
19
 
35
20
  def details
@@ -0,0 +1,51 @@
1
+ module Basecampx
2
+ class Project < Basecampx::Resource
3
+
4
+ attr_accessor :id, :name, :description, :archived, :created_at, :updated_at, :starred, :url
5
+
6
+ def self.all
7
+ Project.parse Basecampx.request "projects.json"
8
+ end
9
+
10
+ def self.find project_id
11
+ Project.new Basecampx.request "projects/#{project_id}.json"
12
+ end
13
+
14
+ def initialize args
15
+ self.update_details args
16
+ end
17
+
18
+ def update_details args
19
+ args.each do |key, value|
20
+ self.send(key.to_s+'=', value) if self.respond_to?((key.to_s+'=').to_s)
21
+ end
22
+ end
23
+
24
+ def self.parse json
25
+ output = []
26
+
27
+ json.each do |user|
28
+ output << self.new(user)
29
+ end
30
+
31
+ output
32
+ end
33
+
34
+ # GET /projects/1/todos/1.json will return the specified todo.
35
+ def todo todo_id
36
+ Todo.new Basecampx.request "projects/#{self.id}/todos/#{todo_id}.json"
37
+ end
38
+
39
+ # GET /projects/1/todolists.json shows active todolists for this project sorted by position.
40
+ # GET /projects/1/todolists/completed.json shows completed todolists for this project.
41
+ def todo_lists completed=false
42
+ TodoList.parse Basecampx.request "projects/#{self.id}/todolists#{completed ? '/completed' : ''}.json"
43
+ end
44
+
45
+ # GET /projects/1/todolists/1.json will return the specified todolist including the todos.
46
+ def todo_list todo_list_id
47
+ TodoList.new Basecampx.request "projects/#{self.id}/todolists/#{todo_list_id}.json"
48
+ end
49
+
50
+ end
51
+ end
@@ -1,6 +1,12 @@
1
1
  module Basecampx
2
- class Todo
2
+ class Todo < Basecampx::Resource
3
+
4
+ attr_accessor :id, :todolist_id, :position, :content, :completed, :due_at, :created_at, :updated_at,
5
+ :comments_count, :creator, :assignee, :comments, :subscribers
6
+
7
+ def self.find project_id, todo_id
8
+ Todo.new Basecampx.request "projects/#{project_id}/todos/#{todo_id}.json"
9
+ end
3
10
 
4
- #attr_accessor :
5
11
  end
6
12
  end
@@ -1,6 +1,26 @@
1
1
  module Basecampx
2
- class TodoList
2
+ class TodoList < Basecampx::Resource
3
+
4
+ attr_accessor :id, :name, :description, :created_at, :updated_at, :completed, :position, :remaining_count,
5
+ :completed_count, :creator, :url, :assigned_todos, :bucket
6
+
7
+ # GET /todolists.json shows active todolists for all projects.
8
+ def self.all
9
+ self.parse Basecampx.request "todolists.json"
10
+ end
11
+
12
+ # GET /todolists/completed.json shows completed todolists for all projects.
13
+ def self.completed
14
+ self.parse Basecampx.request "todolists/completed.json"
15
+ end
16
+
17
+ def self.find project_id, todolist_id
18
+ self.new Basecampx.request "projects/#{project_id}/todolists/#{todolist_id}.json"
19
+ end
20
+
21
+ def todos
22
+
23
+ end
3
24
 
4
- #attr_accessor :
5
25
  end
6
26
  end
@@ -1,3 +1,3 @@
1
1
  module Basecampx
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -24,4 +24,4 @@ module Basecampx
24
24
 
25
25
  end
26
26
  end
27
- end
27
+ end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basecampx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Anton Zaytsev
8
+ - ! '"Anton'
9
+ - Zaytsev"
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-11-08 00:00:00.000000000 Z
13
+ date: 2012-11-13 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: httparty
@@ -45,13 +46,12 @@ dependencies:
45
46
  version: '0'
46
47
  description: Basecamp new ruby api wrapper
47
48
  email:
48
- - me@antonzaytsev.com
49
+ - ! '"me@antonzaytsev.com"'
49
50
  executables: []
50
51
  extensions: []
51
52
  extra_rdoc_files: []
52
53
  files:
53
54
  - .gitignore
54
- - .rvmrc
55
55
  - Gemfile
56
56
  - LICENSE.txt
57
57
  - README.md
@@ -59,7 +59,9 @@ files:
59
59
  - basecampx.gemspec
60
60
  - lib/basecampx.rb
61
61
  - lib/basecampx/base.rb
62
+ - lib/basecampx/resource.rb
62
63
  - lib/basecampx/resources/person.rb
64
+ - lib/basecampx/resources/project.rb
63
65
  - lib/basecampx/resources/todo.rb
64
66
  - lib/basecampx/resources/todo_list.rb
65
67
  - lib/basecampx/version.rb
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use --create 1.9.3@basecampx