teamwork_scrape_client 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/teamwork_scrape_client/client.rb +117 -0
- data/lib/teamwork_scrape_client/project.rb +22 -0
- data/lib/teamwork_scrape_client/version.rb +3 -0
- data/lib/teamwork_scrape_client.rb +6 -0
- data/teamwork_scrape_client.gemspec +27 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 337bf53ee7e80e200b3368492fb654d0c95709f9
|
4
|
+
data.tar.gz: 5786ea834eab1ff0b1734e92faf7d166a2e03df4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7337492ffc3f8fb7c66827a50d6fd0250215fa55faa04330dce088565379f0601ef8c832fc1d5444190d993b4992fbe0275ae053b6df0ae3e9bf8114566efdb7
|
7
|
+
data.tar.gz: f5ea4bf1ed4eda4b10e9a9c07cdcd781e3d4991777c4cf381e8b2416f06ff62ebfb49b2eb669b5891fdb9455c201ce9517a212e6ceced77a27e50e9537cc5049
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Eric Mason
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# TeamworkScrapeClient
|
2
|
+
|
3
|
+
Unofficial Teamwork.com scraping client to supplement the official API. Provides the ability to copy projects.
|
4
|
+
|
5
|
+
**WARNING:** This library uses undocumented APIs intended for use by the Teamwork.com web interface to communicate with the server. If they change the API, this library may break.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'teamwork_scrape_client'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install teamwork_scrape_client
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
client = TeamworkScrapeClient::Client.new(
|
27
|
+
email: 'youremail@example.com',
|
28
|
+
password: 'secret_password',
|
29
|
+
base_url: 'https://yourdomain.teamwork.com'
|
30
|
+
)
|
31
|
+
|
32
|
+
client.copy_project(old_project_id: 12345, new_company_name: "Test Company", new_project_name: "Test Project")
|
33
|
+
```
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ericmason/teamwork_scrape_client.
|
44
|
+
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
49
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "teamwork_scrape_client"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module TeamworkScrapeClient
|
5
|
+
class Client
|
6
|
+
attr_reader :base_url, :email, :password
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@email = options[:email]
|
10
|
+
@password = options[:password]
|
11
|
+
@base_url = options[:base_url]
|
12
|
+
|
13
|
+
raise ArgumentError, 'email is required' unless @email
|
14
|
+
raise ArgumentError, 'password is required' unless @password
|
15
|
+
raise ArgumentError, 'base_url is required' unless @base_url
|
16
|
+
|
17
|
+
login(email, password)
|
18
|
+
end
|
19
|
+
|
20
|
+
def mech
|
21
|
+
@mech ||= Mechanize.new do |m|
|
22
|
+
m.log = Logger.new(STDOUT)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def login(email, password)
|
27
|
+
mech.post(
|
28
|
+
"#{base_url}/v/1/login.json?getInitialPage=true",
|
29
|
+
{ username: email, password: password, rememberMe: false }.to_json,
|
30
|
+
{ 'Content-Type' => 'application/json' }
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def profile
|
35
|
+
response = mech.get('/me.json',
|
36
|
+
fullprofile: 1,
|
37
|
+
getPreferences: 1,
|
38
|
+
cleanPreferences: true,
|
39
|
+
getAccounts: 1,
|
40
|
+
includeAuth: 1,
|
41
|
+
includeClockIn: 1)
|
42
|
+
JSON.parse(response.body)['profile']
|
43
|
+
end
|
44
|
+
|
45
|
+
def account
|
46
|
+
return @account if @account
|
47
|
+
response = mech.get('/account.json')
|
48
|
+
@account = JSON.parse(response.body)['account']
|
49
|
+
end
|
50
|
+
|
51
|
+
def project(id)
|
52
|
+
response = mech.get("/projects/#{id}.json?getPermissions=true&getNotificationSettings=true&getActivePages=true&getDateInfo=true&getEmailAddress=true&formatMarkdown=false")
|
53
|
+
Project.new(JSON.parse(response.body)['project'])
|
54
|
+
end
|
55
|
+
|
56
|
+
def company_by_name(company_name)
|
57
|
+
response = mech.get("/projects.json?getActivePages=true&searchCompany=true&formatMarkdown=false&status=active&getCategoryPath=1&userId=0&page=1&pageSize=500&orderBy=lastActivityDate&orderMode=DESC")
|
58
|
+
projects = JSON.parse(response.body)['projects']
|
59
|
+
companies = projects.map { |p| p['company'] }.uniq
|
60
|
+
companies.find { |c| c['name'] == company_name }
|
61
|
+
end
|
62
|
+
|
63
|
+
def project_by_name(project_name)
|
64
|
+
response = mech.get("/projects.json?getActivePages=true&searchCompany=true&formatMarkdown=false&status=active&getCategoryPath=1&userId=0&page=1&pageSize=500&orderBy=lastActivityDate&orderMode=DESC")
|
65
|
+
JSON.parse(response.body)['projects']
|
66
|
+
end
|
67
|
+
|
68
|
+
def copy_project(options = {})
|
69
|
+
old_project_id = options[:old_project_id]
|
70
|
+
raise ArgumentError, "old_project_id option is required" unless old_project_id
|
71
|
+
|
72
|
+
new_project_name = options[:new_project_name]
|
73
|
+
raise ArgumentError, "new_project_name option is required" unless new_project_name
|
74
|
+
|
75
|
+
new_company_name = options[:new_company_name]
|
76
|
+
raise ArgumentError, "new_company_name option is required" unless new_company_name
|
77
|
+
|
78
|
+
# Find an existing company or add a new one
|
79
|
+
existing_company = company_by_name(new_company_name)
|
80
|
+
existing_company_id = existing_company ? existing_company['id'] : nil
|
81
|
+
|
82
|
+
old_project = project(old_project_id)
|
83
|
+
|
84
|
+
response = mech.post(
|
85
|
+
'/index.cfm',
|
86
|
+
action: 'CloneProject_CreateProjectClone',
|
87
|
+
id: old_project_id,
|
88
|
+
installationId: account['id'],
|
89
|
+
'cloneproject-action' => 'copy',
|
90
|
+
cloneProjectName: new_project_name,
|
91
|
+
copyTasks: 'YES',
|
92
|
+
copyMilestones: 'YES',
|
93
|
+
copyMessages: 'YES',
|
94
|
+
copyFiles: 'YES',
|
95
|
+
copyLinks: 'YES',
|
96
|
+
copyNotebooks: 'YES',
|
97
|
+
copyTimelogs: 'YES',
|
98
|
+
copyInvoices: 'YES',
|
99
|
+
copyExpenses: 'YES',
|
100
|
+
copyRisks: 'YES',
|
101
|
+
copyPeople: 'YES',
|
102
|
+
daysOffset: old_project.days_offset,
|
103
|
+
keepOffWeekends: '1',
|
104
|
+
createActivityLog: 'YES',
|
105
|
+
createItemsUsingCurrentUser: 'NO',
|
106
|
+
uncomplete: 'YES',
|
107
|
+
copyComments: 'YES',
|
108
|
+
copyProjectRoles: 'YES',
|
109
|
+
copyLogo: 'YES',
|
110
|
+
companyId: existing_company_id || 0,
|
111
|
+
newCompanyName: existing_company_id ? '' : new_company_name
|
112
|
+
)
|
113
|
+
|
114
|
+
JSON.parse(response.body)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module TeamworkScrapeClient
|
2
|
+
class Project
|
3
|
+
attr_accessor :attributes
|
4
|
+
|
5
|
+
def initialize(attributes)
|
6
|
+
@attributes = attributes
|
7
|
+
end
|
8
|
+
|
9
|
+
def [](key)
|
10
|
+
attributes[key]
|
11
|
+
end
|
12
|
+
|
13
|
+
def start_date
|
14
|
+
Date.parse(attributes['startDate'])
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns the date offset needed when using this project as a template
|
18
|
+
def days_offset
|
19
|
+
(Date.today - start_date).to_i
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'teamwork_scrape_client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "teamwork_scrape_client"
|
8
|
+
spec.version = TeamworkScrapeClient::VERSION
|
9
|
+
spec.authors = ["Eric Mason"]
|
10
|
+
spec.email = ["eric@equisolve.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Unofficial Teamwork.com scraping client to supplement the official API}
|
13
|
+
spec.description = %q{Unofficial Teamwork.com scraping client to supplement the official API. Provides the ability to copy projects.}
|
14
|
+
spec.homepage = "https://github.com/ericmason/equisolve-teamwork_scrape_client"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
|
26
|
+
spec.add_dependency 'mechanize', '~> 2.7'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: teamwork_scrape_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Mason
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mechanize
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.7'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.7'
|
69
|
+
description: Unofficial Teamwork.com scraping client to supplement the official API.
|
70
|
+
Provides the ability to copy projects.
|
71
|
+
email:
|
72
|
+
- eric@equisolve.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/teamwork_scrape_client.rb
|
87
|
+
- lib/teamwork_scrape_client/client.rb
|
88
|
+
- lib/teamwork_scrape_client/project.rb
|
89
|
+
- lib/teamwork_scrape_client/version.rb
|
90
|
+
- teamwork_scrape_client.gemspec
|
91
|
+
homepage: https://github.com/ericmason/equisolve-teamwork_scrape_client
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.6.7
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Unofficial Teamwork.com scraping client to supplement the official API
|
115
|
+
test_files: []
|