upscrn-client 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.mdown CHANGED
@@ -5,22 +5,144 @@ This is a client for the [upscrn](http://upscrn.com) api.
5
5
 
6
6
  ## Usage
7
7
 
8
+ ====== OLD VERSION (before 0.2.0)======
8
9
  Get the api token from upscrn.com.
9
10
 
10
- Upload a screenshot with:
11
+ Upload a screenshot with:
12
+
13
+ Upscrn::Client.upload_screenshot(filename, auth_token)
11
14
 
12
- UpscrnClient::Client.upload_screenshot(filename, auth_token)
13
-
14
15
  To upload a screenshot to a specific project, use:
15
16
 
16
- UpscrnClient::Client.upload_screenshot(filename, auth_token, :project_id => 12345)
17
-
17
+ Upscrn::Client.upload_screenshot(filename, auth_token, :project_id => 12345)
18
+
18
19
  For a list of a user's projects, use:
19
20
 
20
- UpscrnClient::Client.projects(auth_token)
21
+ Upscrn::Client.projects(auth_token)
22
+
23
+
24
+ ====== NEW VERSION (since 0.2.0) ======
25
+
26
+ ### How To use
27
+
28
+ You can set the auth token in two ways
29
+
30
+ Config:
31
+
32
+ Upscrn::Client.config do |config|
33
+ config.auth_token = 'your_auth_token'
34
+ end
35
+
36
+ Initialization:
37
+
38
+ client = Upscrn::Client.new('your_auth_token')
39
+
40
+
41
+ ### Projects:
42
+
43
+ List all projects:
44
+
45
+ client.projects(:all => true).get
46
+
47
+ client.projects(:page => 2).get
48
+
49
+ Get a project:
50
+
51
+ client.project(project_id).get
52
+
53
+ Create a project:
54
+
55
+ client.projects(:project => {:name => 'test'}).post
56
+
57
+ Edit a project:
58
+
59
+ client.projects(project_id , :project => {:name => 'edited'}).put
60
+
61
+ ### Screenshots:
62
+
63
+ List all Screeshots
64
+
65
+ client.screenshots(:all => true).get
66
+ client.screenshots(:page => 2).get
67
+
68
+ List all Screeshots in a Project
69
+
70
+ client.project(project_id).screenshots(:all => true).get
71
+ client.project(project_id).screenshots(:page => 2).get
72
+
73
+ Create a Screenshot:
74
+
75
+ client.screenshots(:screenshot => {:image => File.open('path/to/image')}).get
76
+
77
+ Create a Screenshot in a Project:
78
+
79
+ client.project(project_id).screenshots(:screenshot => {:title => 'title',:image => File.open('path/to/image')}).post
80
+
81
+ Get a Screenshot
82
+
83
+ client.screenshot(screenshot_id).get
84
+ client.project(project_id).screenshot(screenshot_id).get
85
+
86
+ Create a Comment on a screenshot
87
+
88
+ client.project(project_id).screenshot(screenshot_id).comment(:comment => {:body => 'comment'}).post
89
+
90
+ List all comments on a screenshot
91
+
92
+ client.project(project_id).screenshot(screenshot_id).comments.post
93
+
94
+ List all versions on a screenshot
95
+
96
+ client.project(project_id).screenshot(screenshot_id).versions.post
97
+
98
+ Create a Version on a screenshot
99
+
100
+ client.project(project_id).screenshot(screenshot_id).version(:screenshot => {:title => 'title',:image => File.open('path/to/image')}).post
101
+
102
+ ### Videos:
103
+
104
+ List all Videos
105
+
106
+ client.videos(:all => true).get
107
+ client.videos(:page => 2).get
108
+
109
+ List all Videos in a Project
110
+
111
+ client.project(project_id).videos(:all => true).get
112
+ client.project(project_id).videos(:page => 2).get
113
+
114
+ Create a Video:
115
+
116
+ client.videos(:video => {:image => File.open('path/to/image')}).get
117
+
118
+ Create a Video in a Project:
119
+
120
+ client.project(project_id).videos(:video => {:title => 'title',:file => File.open('path/to/image')}).post
121
+
122
+ Get a Video
123
+
124
+ client.video(video_id).get
125
+ client.project(project_id).video(video_id).get
126
+
127
+ Create a Comment on a Video
128
+
129
+ client.project(project_id).video(video_id).comment(:comment => {:body => 'comment'}).post
130
+
131
+ List all comments on a Video
132
+
133
+ client.project(project_id).video(video_id).comments.post
134
+
135
+ List all versions on a Video
136
+
137
+ client.project(project_id).video(video_id).versions.post
138
+
139
+ Create a Version on a Video
140
+
141
+ client.project(project_id).video(video_id).version(:video => {:title => 'title',:file => File.open('path/to/image')}).post
142
+
21
143
 
22
144
  ## Contributing to upscrn-client
23
-
145
+
24
146
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
25
147
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
26
148
  * Fork the project
data/VERSION CHANGED
@@ -1 +1,2 @@
1
- 0.1.1
1
+ 0.2.0
2
+
data/lib/upscrn-client.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
- require 'json'
3
+ require 'json/pure'
4
4
  require 'rest_client'
5
5
  require File.dirname(__FILE__) + '/upscrn_client/client'
6
6
 
7
- module UpscrnClient
8
- end
7
+ module Upscrn
8
+ end
9
+
@@ -1,13 +1,22 @@
1
- module UpscrnClient
1
+ module Upscrn
2
2
  class Client
3
3
  class << self
4
4
 
5
-
6
- # Upload a screenshot to the upscrn server.
5
+ attr_accessor :auth_token
6
+
7
+ def config
8
+ yield self
9
+ end
10
+
11
+
12
+ #### WARNING: THE CLASS METHODS ARE DEPRECATED
13
+
14
+ # Upload a screenshot to the upscrn server.
7
15
  # Pass :project_id in the options to upload to a particular project
8
-
16
+
9
17
  def upload_screenshot(filename, auth_token, options = {})
10
- puts "filepath: #{filepath}"
18
+ puts "DEPRECATED: will be removed on version 0.3"
19
+ #puts "filepath: #{filepath}"
11
20
  @result = Hash.new
12
21
  @result['success'] = true
13
22
  file = File.open filename, 'r'
@@ -17,42 +26,148 @@ module UpscrnClient
17
26
  else
18
27
  post_response = perform('post', 'screenshots', auth_token, {:screenshot => {:image => file}})
19
28
  end
20
-
21
- puts "response: #{post_response}"
29
+
30
+ #puts "response: #{post_response}"
22
31
  @url = post_response["url"]
23
32
  @result['success'] = true
24
33
  @result['url'] = @url
25
- #clickable_link = NSAttributedString.hyperlinkFromString("See on upscrn", withURL:nsurl)
26
- puts "url = #{@url}"
27
- #@url_label.stringValue = nsurl
28
- #show_screenshot_url(@url, nsurl)
34
+ #puts "url = #{@url}"
29
35
  @url
30
36
  rescue Exception => e
31
- puts "Exception! #{e.message}"
37
+ #puts "Exception! #{e.message}"
32
38
  @result['success'] = false
33
- puts "1"
34
39
  @result['error'] = e.message.to_s
35
- puts "set result"
36
- #@url_label.stringValue = e.message
37
40
  end
38
41
  @result
39
42
  end
40
-
41
-
43
+
44
+
42
45
  # return a list of projects for a given user
43
- # list is returned in json format
46
+ # list is returned in json format
44
47
  def projects(auth_token)
48
+ puts "DEPRECATED: will be removed on version 0.3"
45
49
  perform('get', 'projects', auth_token)
46
50
  end
47
51
 
52
+ private
53
+
48
54
  def perform(verb,action,auth_token, params={})
49
55
  action = [action, 'json'].join('.')
50
56
  url = ['http://upscrn.com', action].join('/')
51
- #url = ['http://127.0.0.1:3000', action].join('/')
52
57
  url = url + "?auth_token=#{auth_token}"
53
- #p url
54
58
  JSON.parse(RestClient.send(verb,url,params).body)
55
59
  end
60
+
61
+ end
62
+
63
+ attr_accessor :auth_token , :resources , :params
64
+
65
+
66
+
67
+ def initialize(auth_token = nil)
68
+ @auth_token = auth_token || self.class.auth_token
69
+ @resources = []
70
+ @params = {}
71
+ end
72
+
73
+
74
+ def projects(params = {})
75
+ tap do
76
+ @resources = ['projects']
77
+ @params.merge!(params)
78
+ end
79
+ end
80
+
81
+ def screenshots(params = {})
82
+ tap do
83
+ @resources += ['screenshots']
84
+ @params.merge!(params)
85
+ end
86
+ end
87
+
88
+ def comments(params = {})
89
+ tap do
90
+ @resources += ['comments']
91
+ @params.merge!(params)
92
+ end
93
+ end
94
+
95
+ def videos(params = {})
96
+ tap do
97
+ @resources += ['videos']
98
+ @params.merge!(params)
99
+ end
100
+ end
101
+
102
+ def project(id , params = {})
103
+ tap do
104
+ @resources = ['projects',id]
105
+ @params.merge!(params)
106
+ end
56
107
  end
108
+
109
+ def screenshot(id , params = {})
110
+ tap do
111
+ @resources += ['screenshots',id]
112
+ @params.merge!(params)
113
+ end
114
+ end
115
+
116
+ def video(id , params = {})
117
+ tap do
118
+ @resources += ['videos',id]
119
+ @params.merge!(params)
120
+ end
121
+ end
122
+
123
+ def comment(params = {})
124
+ tap do
125
+ @resources += ['comments']
126
+ @params.merge!(params)
127
+ end
128
+ end
129
+
130
+
131
+
132
+ def get(clean = true)
133
+ result = client[build_path(@auth_token,@resources,@params)].get
134
+ self.clean if clean
135
+ JSON.parse result
136
+ end
137
+
138
+ def post(clean = true)
139
+ result = client[build_path(@auth_token,@resources)].post(@params)
140
+ self.clean if clean
141
+ JSON.parse result
142
+ end
143
+
144
+ def put(clean = true)
145
+ result = client[build_path(@auth_token,@resources)].put(@params)
146
+ self.clean if clean
147
+ JSON.parse result
148
+ end
149
+
150
+ def clean
151
+ tap do
152
+ @resources = []
153
+ @params = {}
154
+ end
155
+ end
156
+
157
+ private
158
+
159
+ def client
160
+ @client ||= RestClient::Resource.new('http://upscrn.com')
161
+ end
162
+
163
+ def build_path(auth_token,resources , params = {})
164
+ url = resources.join('/')
165
+ url += '.json'
166
+ url += "?" + params.merge(:auth_token => auth_token).to_a.map{|p| p.join('=')}.join('&')
167
+ puts "Path built: #{url}"
168
+ URI.encode(url)
169
+ end
170
+
57
171
  end
58
- end
172
+ end
173
+
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{upscrn-client}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Matt Cowley}]
12
- s.date = %q{2011-09-22}
12
+ s.date = %q{2011-10-10}
13
13
  s.description = %q{client library for accessing the upscrn api}
14
14
  s.email = %q{madcowley@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
34
34
  s.homepage = %q{https://github.com/Yeti-Media/upscrn-client}
35
35
  s.licenses = [%q{MIT}]
36
36
  s.require_paths = [%q{lib}]
37
- s.rubygems_version = %q{1.8.8}
37
+ s.rubygems_version = %q{1.8.5}
38
38
  s.summary = %q{client library for accessing the upscrn api}
39
39
 
40
40
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upscrn-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Cowley
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-22 00:00:00 Z
18
+ date: 2011-10-10 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -27,10 +27,10 @@ dependencies:
27
27
  segments:
28
28
  - 0
29
29
  version: "0"
30
- name: rest-client
31
- prerelease: false
32
30
  type: :runtime
33
31
  requirement: *id001
32
+ prerelease: false
33
+ name: rest-client
34
34
  - !ruby/object:Gem::Dependency
35
35
  version_requirements: &id002 !ruby/object:Gem::Requirement
36
36
  none: false
@@ -41,10 +41,10 @@ dependencies:
41
41
  segments:
42
42
  - 0
43
43
  version: "0"
44
- name: json_pure
45
- prerelease: false
46
44
  type: :runtime
47
45
  requirement: *id002
46
+ prerelease: false
47
+ name: json_pure
48
48
  - !ruby/object:Gem::Dependency
49
49
  version_requirements: &id003 !ruby/object:Gem::Requirement
50
50
  none: false
@@ -57,10 +57,10 @@ dependencies:
57
57
  - 3
58
58
  - 0
59
59
  version: 2.3.0
60
- name: rspec
61
- prerelease: false
62
60
  type: :development
63
61
  requirement: *id003
62
+ prerelease: false
63
+ name: rspec
64
64
  - !ruby/object:Gem::Dependency
65
65
  version_requirements: &id004 !ruby/object:Gem::Requirement
66
66
  none: false
@@ -73,10 +73,10 @@ dependencies:
73
73
  - 0
74
74
  - 0
75
75
  version: 1.0.0
76
- name: bundler
77
- prerelease: false
78
76
  type: :development
79
77
  requirement: *id004
78
+ prerelease: false
79
+ name: bundler
80
80
  - !ruby/object:Gem::Dependency
81
81
  version_requirements: &id005 !ruby/object:Gem::Requirement
82
82
  none: false
@@ -89,10 +89,10 @@ dependencies:
89
89
  - 6
90
90
  - 4
91
91
  version: 1.6.4
92
- name: jeweler
93
- prerelease: false
94
92
  type: :development
95
93
  requirement: *id005
94
+ prerelease: false
95
+ name: jeweler
96
96
  - !ruby/object:Gem::Dependency
97
97
  version_requirements: &id006 !ruby/object:Gem::Requirement
98
98
  none: false
@@ -103,10 +103,10 @@ dependencies:
103
103
  segments:
104
104
  - 0
105
105
  version: "0"
106
- name: rcov
107
- prerelease: false
108
106
  type: :development
109
107
  requirement: *id006
108
+ prerelease: false
109
+ name: rcov
110
110
  description: client library for accessing the upscrn api
111
111
  email: madcowley@gmail.com
112
112
  executables: []
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  requirements: []
160
160
 
161
161
  rubyforge_project:
162
- rubygems_version: 1.8.8
162
+ rubygems_version: 1.8.5
163
163
  signing_key:
164
164
  specification_version: 3
165
165
  summary: client library for accessing the upscrn api