teamwork_scrape_client 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +1 -1
- data/lib/teamwork_scrape_client/client.rb +14 -5
- data/lib/teamwork_scrape_client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f18393aa4a35054b163d73754353e3a2d56eafd2
|
4
|
+
data.tar.gz: d04dd41d431674f7d965a31995d88aed7dfe6e71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f314fdedcdc777ce0f52151939208f2ec05284e782fc1aa9a06df14ba7a0b14e887074867765e5d0f84e25e3888c455dfda195f4cced53cade06651658e33447
|
7
|
+
data.tar.gz: 0eb6b705326e065e3752502380be99b7d6f66bbf54d903752ba53f85ee1ca863e4286787da42f2e197d16565368a0eee677fb0c63e4d0763ac25400677917cda
|
data/README.md
CHANGED
@@ -29,7 +29,7 @@ client = TeamworkScrapeClient::Client.new(
|
|
29
29
|
base_url: 'https://yourdomain.teamwork.com'
|
30
30
|
)
|
31
31
|
|
32
|
-
client.copy_project(
|
32
|
+
client.copy_project(old_project_name: 'Template Project', new_company_name: "Test Company", new_project_name: "Test Project")
|
33
33
|
```
|
34
34
|
|
35
35
|
## Development
|
@@ -3,12 +3,13 @@ require 'json'
|
|
3
3
|
|
4
4
|
module TeamworkScrapeClient
|
5
5
|
class Client
|
6
|
-
attr_reader :base_url, :email, :password
|
6
|
+
attr_reader :base_url, :email, :password, :debug
|
7
7
|
|
8
8
|
def initialize(options = {})
|
9
9
|
@email = options[:email]
|
10
10
|
@password = options[:password]
|
11
11
|
@base_url = options[:base_url]
|
12
|
+
@debug = options[:debug]
|
12
13
|
|
13
14
|
raise ArgumentError, 'email is required' unless @email
|
14
15
|
raise ArgumentError, 'password is required' unless @password
|
@@ -19,7 +20,7 @@ module TeamworkScrapeClient
|
|
19
20
|
|
20
21
|
def mech
|
21
22
|
@mech ||= Mechanize.new do |m|
|
22
|
-
m.log = Logger.new(STDOUT)
|
23
|
+
m.log = Logger.new(STDOUT) if debug
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
@@ -62,12 +63,20 @@ module TeamworkScrapeClient
|
|
62
63
|
|
63
64
|
def project_by_name(project_name)
|
64
65
|
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
|
+
projects = JSON.parse(response.body)['projects']
|
67
|
+
projects.find { |p| p['name'] == project_name }
|
66
68
|
end
|
67
69
|
|
68
70
|
def copy_project(options = {})
|
69
|
-
old_project_id
|
70
|
-
|
71
|
+
raise ArgumentError, "old_project_id or old_project_name option is required" unless options[:old_project_name] || options[:old_project_id]
|
72
|
+
|
73
|
+
old_project_id = if options[:old_project_name]
|
74
|
+
old_project = project_by_name(old_project_name)
|
75
|
+
raise "Project #{options[:old_project_name]} not found" unless old_project
|
76
|
+
old_project['id']
|
77
|
+
else
|
78
|
+
options[:old_project_id]
|
79
|
+
end
|
71
80
|
|
72
81
|
new_project_name = options[:new_project_name]
|
73
82
|
raise ArgumentError, "new_project_name option is required" unless new_project_name
|