wsnaps 1.0 → 1.0.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/lib/worksnaps/api/arguments.rb +13 -0
- data/lib/worksnaps/api/projects.rb +26 -0
- data/lib/worksnaps/api/task_assignments.rb +26 -0
- data/lib/worksnaps/api/tasks.rb +30 -0
- data/lib/worksnaps/api/time_entries.rb +30 -0
- data/lib/worksnaps/api/user_assignments.rb +30 -0
- data/lib/worksnaps/api/users.rb +26 -0
- data/lib/worksnaps/api/utils.rb +182 -0
- data/lib/worksnaps/base.rb +117 -0
- data/lib/worksnaps/client.rb +76 -0
- data/lib/worksnaps/default.rb +94 -0
- data/lib/worksnaps/error.rb +22 -0
- data/lib/worksnaps/error/already_favorited.rb +10 -0
- data/lib/worksnaps/error/already_retweeted.rb +10 -0
- data/lib/worksnaps/error/bad_gateway.rb +11 -0
- data/lib/worksnaps/error/bad_request.rb +10 -0
- data/lib/worksnaps/error/client_error.rb +35 -0
- data/lib/worksnaps/error/configuration_error.rb +8 -0
- data/lib/worksnaps/error/decode_error.rb +9 -0
- data/lib/worksnaps/error/forbidden.rb +10 -0
- data/lib/worksnaps/error/gateway_timeout.rb +11 -0
- data/lib/worksnaps/error/identity_map_key_error.rb +9 -0
- data/lib/worksnaps/error/internal_server_error.rb +11 -0
- data/lib/worksnaps/error/not_acceptable.rb +10 -0
- data/lib/worksnaps/error/not_found.rb +10 -0
- data/lib/worksnaps/error/server_error.rb +28 -0
- data/lib/worksnaps/error/service_unavailable.rb +11 -0
- data/lib/worksnaps/error/too_many_requests.rb +12 -0
- data/lib/worksnaps/error/unauthorized.rb +8 -0
- data/lib/worksnaps/error/unprocessable_entity.rb +10 -0
- data/lib/worksnaps/helper.rb +37 -0
- data/lib/worksnaps/project.rb +7 -0
- data/lib/worksnaps/request/multipart_with_file.rb +34 -0
- data/lib/worksnaps/response/parse_json.rb +25 -0
- data/lib/worksnaps/response/parse_xml.rb +25 -0
- data/lib/worksnaps/response/raise_error.rb +33 -0
- data/lib/worksnaps/task.rb +7 -0
- data/lib/worksnaps/task_assignment.rb +7 -0
- data/lib/worksnaps/user.rb +13 -0
- data/lib/worksnaps/user_assignment.rb +7 -0
- data/lib/worksnaps/version.rb +14 -0
- data/lib/wsnaps.rb +68 -3
- metadata +44 -3
@@ -0,0 +1,37 @@
|
|
1
|
+
class Hash
|
2
|
+
def to_xml(depth = 0)
|
3
|
+
map{|k,v|
|
4
|
+
body = v.is_a?(Hash) ? ("\n" + v.to_xml(depth + 1)) : v.to_s
|
5
|
+
"%s<%s>%s</%s>\n" % [" " * depth, k.to_s, body, k.to_s]
|
6
|
+
}.join
|
7
|
+
end
|
8
|
+
|
9
|
+
def symbolize_keys!
|
10
|
+
inject({}) {|m, (k,v)|
|
11
|
+
m[k.to_sym] = v.is_a?(Hash) ? v.symbolize_keys! : v
|
12
|
+
m
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
=begin
|
18
|
+
class String
|
19
|
+
def demodulize
|
20
|
+
if i = self.rindex('::')
|
21
|
+
self[(i+2)..-1]
|
22
|
+
else
|
23
|
+
self
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def underscore
|
28
|
+
self.gsub!(/::/, '/')
|
29
|
+
self.gsub!(/(?:([A-Za-z\d])|^)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" }
|
30
|
+
self.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
|
31
|
+
self.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
32
|
+
self.tr!("-", "_")
|
33
|
+
self.downcase!
|
34
|
+
self + 's'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
=end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module WorkSnaps
|
4
|
+
module Request
|
5
|
+
class MultipartWithFile < Faraday::Middleware
|
6
|
+
CONTENT_TYPE = 'Content-Type'
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
env[:body].each do |key, value|
|
10
|
+
if value.respond_to?(:to_io)
|
11
|
+
env[:body][key] = Faraday::UploadIO.new(value, mime_type(value.path), value.path)
|
12
|
+
end
|
13
|
+
end if env[:body].is_a?(::Hash)
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def mime_type(path)
|
20
|
+
case path
|
21
|
+
when /\.jpe?g/i
|
22
|
+
'image/jpeg'
|
23
|
+
when /\.gif$/i
|
24
|
+
'image/gif'
|
25
|
+
when /\.png$/i
|
26
|
+
'image/png'
|
27
|
+
else
|
28
|
+
'application/octet-stream'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module WorkSnaps
|
5
|
+
module Response
|
6
|
+
class ParseJson < Faraday::Response::Middleware
|
7
|
+
|
8
|
+
def parse(body)
|
9
|
+
case body
|
10
|
+
when /\A^\s*$\z/, nil
|
11
|
+
nil
|
12
|
+
else
|
13
|
+
MultiJson.decode(body, :symbolize_keys => true)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def on_complete(env)
|
18
|
+
if respond_to?(:parse)
|
19
|
+
env[:body] = parse(env[:body]) unless [204, 301, 302, 304].include?(env[:status])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'crack/xml'
|
3
|
+
|
4
|
+
module WorkSnaps
|
5
|
+
module Response
|
6
|
+
class ParseXML < Faraday::Response::Middleware
|
7
|
+
|
8
|
+
def parse(body)
|
9
|
+
body = Crack::XML.parse(body)
|
10
|
+
if body['method'] == :post or body['method'] == :put
|
11
|
+
reply = body.delete('reply')
|
12
|
+
body.merge reply if reply.is_a(Hash)
|
13
|
+
end
|
14
|
+
body
|
15
|
+
end
|
16
|
+
|
17
|
+
def on_complete(env)
|
18
|
+
if respond_to?(:parse)
|
19
|
+
env[:body] = parse(env[:body]) unless [204, 301, 302, 304].include?(env[:status])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
=begin
|
3
|
+
require 'worksnaps/error/bad_gateway'
|
4
|
+
require 'worksnaps/error/bad_request'
|
5
|
+
require 'worksnaps/error/forbidden'
|
6
|
+
require 'worksnaps/error/gateway_timeout'
|
7
|
+
require 'worksnaps/error/internal_server_error'
|
8
|
+
require 'worksnaps/error/not_acceptable'
|
9
|
+
require 'worksnaps/error/not_found'
|
10
|
+
require 'worksnaps/error/service_unavailable'
|
11
|
+
require 'worksnaps/error/too_many_requests'
|
12
|
+
require 'worksnaps/error/unauthorized'
|
13
|
+
require 'worksnaps/error/unprocessable_entity'
|
14
|
+
=end
|
15
|
+
|
16
|
+
module WorkSnaps
|
17
|
+
module Response
|
18
|
+
class RaiseError < Faraday::Response::Middleware
|
19
|
+
|
20
|
+
def on_complete(env)
|
21
|
+
status_code = env[:status].to_i
|
22
|
+
error_class = @klass.errors[status_code]
|
23
|
+
raise error_class.from_response(env) if error_class
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(app, klass)
|
27
|
+
@klass = klass
|
28
|
+
super(app)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'worksnaps/base'
|
2
|
+
|
3
|
+
module WorkSnaps
|
4
|
+
class User < Base
|
5
|
+
attr_reader :id, :login, :first_name, :last_name, :password,
|
6
|
+
:email, :timezone_id, :is_in_daylight_time, :timezone_name
|
7
|
+
|
8
|
+
def full_name
|
9
|
+
[last_name, first_name].join(', ')
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module WorkSnaps
|
2
|
+
class Version
|
3
|
+
MAJOR = 1 unless defined? WorkSnaps::Version::MAJOR
|
4
|
+
MINOR = 0 unless defined? WorkSnaps::Version::MINOR
|
5
|
+
PATCH = 0 unless defined? WorkSnaps::Version::PATCH
|
6
|
+
PRE = nil unless defined? WorkSnaps::Version::PRE
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def to_s
|
10
|
+
[MAJOR, MINOR, PATCH, PRE].compact.join('.')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/wsnaps.rb
CHANGED
@@ -1,5 +1,70 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'active_support/inflector'
|
3
|
+
require 'worksnaps/helper'
|
4
|
+
require 'worksnaps/client'
|
5
|
+
require 'worksnaps/default'
|
6
|
+
|
7
|
+
module Wsnaps
|
8
|
+
class << self
|
9
|
+
extend Forwardable
|
10
|
+
attr_writer :api_tocken, :consumer_key, :consumer_secret, :oauth_token, :oauth_token_secret
|
11
|
+
attr_accessor :endpoint, :connection_options, :identity_map, :middleware
|
12
|
+
def_delegator :options, :hash
|
13
|
+
|
14
|
+
def snap
|
15
|
+
puts "-- snap --"
|
16
|
+
end
|
17
|
+
|
18
|
+
def keys
|
19
|
+
@keys ||= [
|
20
|
+
:api_tocken,
|
21
|
+
:consumer_key,
|
22
|
+
:consumer_secret,
|
23
|
+
:oauth_token,
|
24
|
+
:oauth_token_secret,
|
25
|
+
:endpoint,
|
26
|
+
:connection_options,
|
27
|
+
:identity_map,
|
28
|
+
:middleware,
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
def oauth_credentials
|
33
|
+
{
|
34
|
+
:consumer_key => @consumer_key,
|
35
|
+
:consumer_secret => @consumer_secret,
|
36
|
+
:token => @oauth_token,
|
37
|
+
:token_secret => @oauth_token_secret,
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def api_tocken
|
42
|
+
@api_tocken
|
43
|
+
end
|
44
|
+
|
45
|
+
def configure
|
46
|
+
yield self
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
def reset!
|
51
|
+
keys.each do |key|
|
52
|
+
instance_variable_set(:"@#{key}", WorkSnaps::Default.options[key])
|
53
|
+
end
|
54
|
+
self
|
55
|
+
end
|
56
|
+
alias setup reset!
|
57
|
+
|
58
|
+
def client
|
59
|
+
@client ||= WorkSnaps::Client.new
|
60
|
+
end
|
61
|
+
|
62
|
+
def respond_to_missing?(method_name, include_private=false); client.respond_to?(method_name, include_private); end if RUBY_VERSION >= "1.9"
|
63
|
+
def respond_to?(method_name, include_private=false); client.respond_to?(method_name, include_private) || super; end if RUBY_VERSION < "1.9"
|
64
|
+
|
65
|
+
def method_missing(method_name, *args, &block)
|
66
|
+
return super unless client.respond_to?(method_name)
|
67
|
+
client.send(method_name, *args, &block)
|
68
|
+
end
|
4
69
|
end
|
5
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wsnaps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GisAk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Go and Die
|
14
14
|
email: guna@egrovesystems.com
|
@@ -16,6 +16,47 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- lib/worksnaps/api/arguments.rb
|
20
|
+
- lib/worksnaps/api/projects.rb
|
21
|
+
- lib/worksnaps/api/task_assignments.rb
|
22
|
+
- lib/worksnaps/api/tasks.rb
|
23
|
+
- lib/worksnaps/api/time_entries.rb
|
24
|
+
- lib/worksnaps/api/user_assignments.rb
|
25
|
+
- lib/worksnaps/api/users.rb
|
26
|
+
- lib/worksnaps/api/utils.rb
|
27
|
+
- lib/worksnaps/base.rb
|
28
|
+
- lib/worksnaps/client.rb
|
29
|
+
- lib/worksnaps/default.rb
|
30
|
+
- lib/worksnaps/error.rb
|
31
|
+
- lib/worksnaps/error/already_favorited.rb
|
32
|
+
- lib/worksnaps/error/already_retweeted.rb
|
33
|
+
- lib/worksnaps/error/bad_gateway.rb
|
34
|
+
- lib/worksnaps/error/bad_request.rb
|
35
|
+
- lib/worksnaps/error/client_error.rb
|
36
|
+
- lib/worksnaps/error/configuration_error.rb
|
37
|
+
- lib/worksnaps/error/decode_error.rb
|
38
|
+
- lib/worksnaps/error/forbidden.rb
|
39
|
+
- lib/worksnaps/error/gateway_timeout.rb
|
40
|
+
- lib/worksnaps/error/identity_map_key_error.rb
|
41
|
+
- lib/worksnaps/error/internal_server_error.rb
|
42
|
+
- lib/worksnaps/error/not_acceptable.rb
|
43
|
+
- lib/worksnaps/error/not_found.rb
|
44
|
+
- lib/worksnaps/error/server_error.rb
|
45
|
+
- lib/worksnaps/error/service_unavailable.rb
|
46
|
+
- lib/worksnaps/error/too_many_requests.rb
|
47
|
+
- lib/worksnaps/error/unauthorized.rb
|
48
|
+
- lib/worksnaps/error/unprocessable_entity.rb
|
49
|
+
- lib/worksnaps/helper.rb
|
50
|
+
- lib/worksnaps/project.rb
|
51
|
+
- lib/worksnaps/request/multipart_with_file.rb
|
52
|
+
- lib/worksnaps/response/parse_json.rb
|
53
|
+
- lib/worksnaps/response/parse_xml.rb
|
54
|
+
- lib/worksnaps/response/raise_error.rb
|
55
|
+
- lib/worksnaps/task.rb
|
56
|
+
- lib/worksnaps/task_assignment.rb
|
57
|
+
- lib/worksnaps/user.rb
|
58
|
+
- lib/worksnaps/user_assignment.rb
|
59
|
+
- lib/worksnaps/version.rb
|
19
60
|
- lib/wsnaps.rb
|
20
61
|
homepage: http://rubygems.org/gems/wsnaps
|
21
62
|
licenses:
|
@@ -37,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
78
|
version: '0'
|
38
79
|
requirements: []
|
39
80
|
rubyforge_project:
|
40
|
-
rubygems_version: 2.6.
|
81
|
+
rubygems_version: 2.6.8
|
41
82
|
signing_key:
|
42
83
|
specification_version: 4
|
43
84
|
summary: test gem check
|