stdd-api 0.1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/stdd_api.rb +128 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f7a820ec805b4aa9113f70ea34c851a0b3b348ea
|
4
|
+
data.tar.gz: 32af1224b28f0be6c94bf9e337ac0f8acfd426dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e1f10ff77a771ad42ca3017eb30113c2198e3ccd7a1c545871824ca0984fd98022da8f976026448886980deb845b6ee1466b8f5ffc5c3df4a0aa5a18f29b184
|
7
|
+
data.tar.gz: 50b7c69afa4c019de58f2f58c3515e1df60690a40075ad417ca2c18c905e91cc651a64b24b5c39b4e0d373455027af3ab39c5e45b272f1ac49c4a39a37f96d8b
|
data/lib/stdd_api.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'cgi'
|
3
|
+
|
4
|
+
|
5
|
+
class STDDAPI
|
6
|
+
|
7
|
+
def initialize(stdd_url,http_proxy)
|
8
|
+
puts "hej"
|
9
|
+
@url = stdd_url ? stdd_url : ['http://www.stddtool.se']
|
10
|
+
@proxy = http_proxy ? URI.parse('http://'+http_proxy) : OpenStruct.new
|
11
|
+
@connection_error = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_customer customer_name
|
15
|
+
return if @connection_error
|
16
|
+
p "Creating customer.."
|
17
|
+
uri = URI.parse(@url)
|
18
|
+
|
19
|
+
begin
|
20
|
+
http = Net::HTTP::Proxy(@proxy.host, @proxy.port).new(uri.host, uri.port)
|
21
|
+
request = Net::HTTP::Post.new("/api/create_customer",initheader = { 'Content-Type' => 'application/json'})
|
22
|
+
request.body = {"name" => customer_name}.to_json
|
23
|
+
response = http.request(request)
|
24
|
+
case response.code
|
25
|
+
when /20\d/
|
26
|
+
#success
|
27
|
+
else
|
28
|
+
@connection_error = response.body
|
29
|
+
end
|
30
|
+
|
31
|
+
parsed = JSON.parse(response.body)
|
32
|
+
if parsed["error"]
|
33
|
+
@connection_error = parsed["error"]
|
34
|
+
else
|
35
|
+
customer_id = parsed["_id"]
|
36
|
+
end
|
37
|
+
|
38
|
+
rescue
|
39
|
+
@connection_error = "COULD NOT CONNECT TO HOST AT: #{@url}"
|
40
|
+
end
|
41
|
+
|
42
|
+
if(@connection_error)
|
43
|
+
@io.puts @connection_error
|
44
|
+
else
|
45
|
+
return customer_id
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_customer(customer_name)
|
51
|
+
customer = Customer.new(customer_name)
|
52
|
+
|
53
|
+
# get existing customer
|
54
|
+
if @connection_error
|
55
|
+
@io.puts "#{@connection_error}"
|
56
|
+
return
|
57
|
+
end
|
58
|
+
|
59
|
+
uri = URI.parse(@url)
|
60
|
+
|
61
|
+
path = "/api/get_customer"
|
62
|
+
path = add_params_to_path(path,{:name => customer.name})
|
63
|
+
|
64
|
+
req = Net::HTTP::Get.new(path,)
|
65
|
+
response = Net::HTTP::Proxy(@proxy.host, @proxy.port).new(uri.host, uri.port).start {|http|
|
66
|
+
http.request(req)
|
67
|
+
}
|
68
|
+
|
69
|
+
parsed = JSON.parse(response.body)
|
70
|
+
|
71
|
+
if(parsed["_id"])
|
72
|
+
customer.id = parsed["_id"]
|
73
|
+
else
|
74
|
+
customer = create_customer(customer.name)
|
75
|
+
end
|
76
|
+
|
77
|
+
return customer
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
def add_params_to_path (path, params)
|
82
|
+
if(params)
|
83
|
+
path = "#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&'))
|
84
|
+
end
|
85
|
+
return path
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
class Customer
|
94
|
+
def initialize(name)
|
95
|
+
@name = name
|
96
|
+
end
|
97
|
+
attr_accessor :name,:id
|
98
|
+
def to_s
|
99
|
+
"name: #{@name}, id: #{@id}"
|
100
|
+
end
|
101
|
+
def to_json
|
102
|
+
{'name' => @name}.to_json
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class Project
|
107
|
+
def initialize(customer_id,name)
|
108
|
+
@name = name
|
109
|
+
@customer_id = customer_id
|
110
|
+
end
|
111
|
+
attr_accessor :name,:id,:customer_id
|
112
|
+
def to_json
|
113
|
+
{'name' => @name,'customer_id:' => customer_id}.to_json
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
class Run
|
118
|
+
def initialize(name)
|
119
|
+
@name = name
|
120
|
+
@start_time = Time.now
|
121
|
+
end
|
122
|
+
attr_accessor :name,:ID
|
123
|
+
def to_json
|
124
|
+
{'name' => @name,'start_time' => @start_time}.to_json
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stdd-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anton Danielsson
|
8
|
+
- Anders Åslund
|
9
|
+
- Learningwell West
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2014-03-07 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: API for reporting to stddtool
|
16
|
+
email: anton.danielsson@learningwell.se
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/stdd_api.rb
|
22
|
+
homepage: https://github.com/LearningWellWest/ruby-stdd
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.0.3
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: API for stddtool
|
46
|
+
test_files: []
|