citrulu 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.
- data/README.md +60 -6
- data/Rakefile +11 -11
- data/VERSION +1 -1
- data/citrulu.gemspec +2 -2
- data/lib/citrulu.rb +2 -1
- data/lib/citrulu/error.rb +1 -1
- data/lib/citrulu/test_file.rb +46 -27
- data/lib/faraday/raise_error.rb +1 -0
- metadata +4 -4
data/README.md
CHANGED
|
@@ -1,17 +1,69 @@
|
|
|
1
1
|
Citrulu
|
|
2
2
|
=======
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
[Citrulu](https://www.citrulu.com/) exposes an [api](https://www.citrulu.com/api) for creating, editing and compiling test files. This gem provides a wrapper around that api which allows you to work with TestFile objects locally.
|
|
5
|
+
|
|
6
|
+
The gem has not yet been widely used. It's probably very unlikely to cause anything bad to happen in your app, but please **use at your own risk** and raise an issue if you find any bugs.
|
|
7
|
+
|
|
8
|
+
Installation
|
|
9
|
+
-------------
|
|
10
|
+
|
|
11
|
+
gem install citrulu
|
|
12
|
+
|
|
13
|
+
Or in your gemfile:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem "citrulu"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Setup
|
|
20
|
+
-----
|
|
21
|
+
|
|
22
|
+
You need an account on Citrulu to use the gem: Sign up at <http://www.citrulu.com>, and once you're signed in you can create an API key on the '[Account Settings](https://www.citrulu.com/settings)' page.
|
|
23
|
+
|
|
24
|
+
Configure your API key by adding it to an initializer:
|
|
25
|
+
|
|
26
|
+
```ruby
|
|
27
|
+
#config/initializers/citrulu_auth.rb
|
|
28
|
+
CITRULU_API_KEY = "abcdefgh"
|
|
29
|
+
```
|
|
4
30
|
|
|
5
31
|
Usage
|
|
6
32
|
-----
|
|
7
|
-
You need an account on Citrulu to use the gem. Sign up at <http://www.citrulu.com>.
|
|
8
33
|
|
|
9
|
-
You can
|
|
34
|
+
You can interact with TestFile instances in mostly the same way that you'd interact with a Rails model:
|
|
10
35
|
|
|
11
|
-
|
|
36
|
+
List test files
|
|
12
37
|
|
|
13
38
|
```ruby
|
|
14
|
-
|
|
39
|
+
TestFile.all
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Create a new test file
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
test_file = TestFile.new( name: "My first test file",
|
|
46
|
+
test_file_text: "On http://www.google.com",
|
|
47
|
+
run_tests: "true" )
|
|
48
|
+
test_file.save
|
|
49
|
+
|
|
50
|
+
# test files must have be successfully compiled before they will be run:
|
|
51
|
+
test_file.compile
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Find a specific test file by and update it:
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
test_file = TestFile.find(23)
|
|
58
|
+
test_file.update(run_tests: false)
|
|
59
|
+
test_file.save
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Delete a test file:
|
|
63
|
+
|
|
64
|
+
```ruby
|
|
65
|
+
test_file = TestFile.find(23)
|
|
66
|
+
test_file.destroy
|
|
15
67
|
```
|
|
16
68
|
|
|
17
69
|
Contributing to the Citrulu gem
|
|
@@ -28,6 +80,8 @@ Authors
|
|
|
28
80
|
-------
|
|
29
81
|
Duncan Stuart (duncan@dxw.com)
|
|
30
82
|
|
|
83
|
+
contact@dxw.com
|
|
84
|
+
|
|
31
85
|
Copyright
|
|
32
86
|
---------
|
|
33
|
-
Copyright (c) 2012 The Dextrous Web Ltd. See LICENSE.txt for further details.
|
|
87
|
+
Copyright (c) 2012 The Dextrous Web Ltd. See LICENSE.txt for further details.
|
data/Rakefile
CHANGED
|
@@ -17,8 +17,8 @@ Jeweler::Tasks.new do |gem|
|
|
|
17
17
|
gem.name = "citrulu"
|
|
18
18
|
gem.homepage = "https://github.com/dxw/citrulu-api-ruby.git"
|
|
19
19
|
gem.license = "MIT"
|
|
20
|
-
gem.summary = %Q{
|
|
21
|
-
gem.description = %Q{
|
|
20
|
+
gem.summary = %Q{Wrapper for the api exposed by Citrulu}
|
|
21
|
+
gem.description = %Q{Citrulu exposes an api for creating, editing and compiling test files (http://www.citrulu.com/api). This gem provides a wrapper around that api which allows you to work with TestFile objects locally.}
|
|
22
22
|
gem.email = ["contact@dxw.com", "duncan@dxw.com"]
|
|
23
23
|
gem.authors = ["Duncan Stuart"]
|
|
24
24
|
# dependencies defined in Gemfile
|
|
@@ -38,12 +38,12 @@ end
|
|
|
38
38
|
|
|
39
39
|
task :default => :spec
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
require 'rdoc/task'
|
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
|
44
|
+
|
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
46
|
+
rdoc.title = "citrulu-api #{version}"
|
|
47
|
+
rdoc.rdoc_files.include('README*')
|
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
49
|
+
end
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.1
|
data/citrulu.gemspec
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = "citrulu"
|
|
8
|
-
s.version = "0.1.
|
|
8
|
+
s.version = "0.1.1"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Duncan Stuart"]
|
|
12
12
|
s.date = "2012-10-29"
|
|
13
|
-
s.description = "
|
|
13
|
+
s.description = "Citrulu exposes an api for creating, editing and compiling test files (http://www.citrulu.com/api). This gem provides a wrapper around that api which allows you to work with TestFile objects locally."
|
|
14
14
|
s.email = ["contact@dxw.com", "duncan@dxw.com"]
|
|
15
15
|
s.extra_rdoc_files = [
|
|
16
16
|
"LICENSE.txt",
|
data/lib/citrulu.rb
CHANGED
|
@@ -3,9 +3,10 @@ Dir[File.expand_path('../faraday/*.rb', __FILE__)].each{|f| require f}
|
|
|
3
3
|
require 'faraday'
|
|
4
4
|
|
|
5
5
|
module Citrulu
|
|
6
|
+
# The address of the Citrulu API
|
|
6
7
|
BASE_URL = "https://www.citrulu.com/api/v1"
|
|
7
|
-
# BASE_URL = "http://localhost:3000/api/v1"
|
|
8
8
|
|
|
9
|
+
# Sets up the connection to the Citrulu API using the api key, which must already have been set to CITRULU_API_KEY
|
|
9
10
|
def self.connection
|
|
10
11
|
Faraday.new(:url => BASE_URL) do |connection|
|
|
11
12
|
connection.request :url_encoded # form-encode POST params
|
data/lib/citrulu/error.rb
CHANGED
data/lib/citrulu/test_file.rb
CHANGED
|
@@ -4,18 +4,25 @@ require 'active_model'
|
|
|
4
4
|
class TestFile
|
|
5
5
|
attr_accessor :name
|
|
6
6
|
attr_accessor :test_file_text
|
|
7
|
+
# The tests which will be run. May differ from test_file_text if the
|
|
7
8
|
attr_reader :compiled_test_file_text
|
|
9
|
+
# Boolean - if set to true, the tests will be run
|
|
8
10
|
attr_accessor :run_tests
|
|
11
|
+
# The list of domains in compiled_test_file_text
|
|
9
12
|
attr_reader :domains
|
|
13
|
+
# How often the test file is run, in seconds (e.g. 3600 = once every hour)
|
|
10
14
|
attr_reader :frequency
|
|
11
15
|
attr_reader :id
|
|
12
16
|
attr_reader :tutorial_id
|
|
13
17
|
attr_reader :updated_at
|
|
14
18
|
attr_reader :created_at
|
|
15
19
|
|
|
20
|
+
# A rails style error object (using ActiveModel::Errors) - use errors.full_messages to access an array of error messages
|
|
16
21
|
attr_reader :errors
|
|
17
22
|
|
|
18
|
-
|
|
23
|
+
protected
|
|
24
|
+
|
|
25
|
+
def self.attribute_method?(attribute) #:nodoc:
|
|
19
26
|
[ :name,
|
|
20
27
|
:test_file_text,
|
|
21
28
|
:compiled_test_file_text,
|
|
@@ -29,27 +36,38 @@ class TestFile
|
|
|
29
36
|
].include?(attribute)
|
|
30
37
|
end
|
|
31
38
|
|
|
39
|
+
public
|
|
40
|
+
|
|
32
41
|
extend ActiveModel::Naming
|
|
33
42
|
# Required dependency for ActiveModel::Errors
|
|
34
43
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
class << self
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
# Required in order for ActiveModel::Errors to work correctly
|
|
48
|
+
def self.human_attribute_name(attr, options = {})
|
|
49
|
+
attr
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Required in order for ActiveModel::Errors to work correctly
|
|
53
|
+
def self.lookup_ancestors
|
|
54
|
+
[self]
|
|
55
|
+
end
|
|
40
56
|
end
|
|
41
57
|
|
|
42
|
-
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
# Required in order for ActiveModel::Errors to work correctly
|
|
43
61
|
def read_attribute_for_validation(attr)
|
|
44
62
|
send(attr)
|
|
45
63
|
end
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
64
|
+
|
|
65
|
+
public
|
|
66
|
+
|
|
67
|
+
def initialize(args={})
|
|
68
|
+
args.each do |attr, value|
|
|
69
|
+
self.public_send("#{attr}=", value)
|
|
70
|
+
end if args
|
|
53
71
|
end
|
|
54
72
|
|
|
55
73
|
|
|
@@ -84,7 +102,7 @@ class TestFile
|
|
|
84
102
|
build(body)
|
|
85
103
|
else # 422 - validation errors
|
|
86
104
|
test_file = build(options)
|
|
87
|
-
|
|
105
|
+
add_all_errors(test_file, body["errors"])
|
|
88
106
|
return test_file
|
|
89
107
|
end
|
|
90
108
|
end
|
|
@@ -98,7 +116,7 @@ class TestFile
|
|
|
98
116
|
build(body)
|
|
99
117
|
else # 422 - validation errors
|
|
100
118
|
test_file = find(id)
|
|
101
|
-
|
|
119
|
+
add_all_errors(test_file, body["errors"])
|
|
102
120
|
return test_file
|
|
103
121
|
end
|
|
104
122
|
end
|
|
@@ -121,7 +139,7 @@ class TestFile
|
|
|
121
139
|
# Instance Methods #
|
|
122
140
|
####################
|
|
123
141
|
|
|
124
|
-
# Create or update the current
|
|
142
|
+
# Create or update the current test file on Citrulu
|
|
125
143
|
def save
|
|
126
144
|
options = { name: name,
|
|
127
145
|
test_file_text: test_file_text,
|
|
@@ -134,10 +152,12 @@ class TestFile
|
|
|
134
152
|
end
|
|
135
153
|
end
|
|
136
154
|
|
|
155
|
+
# Deletes the current test file on Citrulu
|
|
137
156
|
def destroy
|
|
138
157
|
self.class.delete(id)
|
|
139
158
|
end
|
|
140
159
|
|
|
160
|
+
# Attempts to compile the test file. Returns any compilation errors as an errors object. Use errors.full_messages to access the array of error messages.
|
|
141
161
|
def compile
|
|
142
162
|
self.class.compile(id)
|
|
143
163
|
end
|
|
@@ -150,7 +170,6 @@ class TestFile
|
|
|
150
170
|
# Utility Methods #
|
|
151
171
|
####################
|
|
152
172
|
|
|
153
|
-
#TODO: really not sure about this...
|
|
154
173
|
class << self
|
|
155
174
|
private
|
|
156
175
|
|
|
@@ -165,17 +184,17 @@ class TestFile
|
|
|
165
184
|
return test_file
|
|
166
185
|
end
|
|
167
186
|
|
|
187
|
+
def add_all_errors(test_file, error_hash)
|
|
188
|
+
error_hash.each do |attribute, messages|
|
|
189
|
+
messages.each do |message|
|
|
190
|
+
test_file.errors.add(attribute.to_sym, message)
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
168
195
|
def parse_response(json)
|
|
169
196
|
attrs = JSON.parse(json)
|
|
170
197
|
build(attrs)
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
def add_all_errors(error_hash)
|
|
175
|
-
error_hash.each do |attribute, messages|
|
|
176
|
-
messages.each do |message|
|
|
177
|
-
errors.add(attribute.to_sym, message)
|
|
178
|
-
end
|
|
179
|
-
end
|
|
198
|
+
end
|
|
180
199
|
end
|
|
181
200
|
end
|
data/lib/faraday/raise_error.rb
CHANGED
|
@@ -5,6 +5,7 @@ require 'faraday'
|
|
|
5
5
|
|
|
6
6
|
module FaradayMiddleware
|
|
7
7
|
class RaiseHttpException < Faraday::Middleware
|
|
8
|
+
# Handle response codes 401, 404 and 500 as exceptions. See https://github.com/technoweenie/faraday#writing-middleware for more details.
|
|
8
9
|
def call(env)
|
|
9
10
|
@app.call(env).on_complete do |response|
|
|
10
11
|
case response[:status].to_i
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: citrulu
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -155,9 +155,9 @@ dependencies:
|
|
|
155
155
|
- - ! '>='
|
|
156
156
|
- !ruby/object:Gem::Version
|
|
157
157
|
version: '0'
|
|
158
|
-
description:
|
|
158
|
+
description: Citrulu exposes an api for creating, editing and compiling test files
|
|
159
159
|
(http://www.citrulu.com/api). This gem provides a wrapper around that api which
|
|
160
|
-
allows you to work with TestFile objects locally.
|
|
160
|
+
allows you to work with TestFile objects locally.
|
|
161
161
|
email:
|
|
162
162
|
- contact@dxw.com
|
|
163
163
|
- duncan@dxw.com
|
|
@@ -199,7 +199,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
199
199
|
version: '0'
|
|
200
200
|
segments:
|
|
201
201
|
- 0
|
|
202
|
-
hash:
|
|
202
|
+
hash: -1012160131491449687
|
|
203
203
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
204
|
none: false
|
|
205
205
|
requirements:
|