tixriss 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3367b2fd6e1be04ddb6737ece0418d7f09f647a1
4
+ data.tar.gz: b9ec290c9d1ba60eaad19ed083efc7ca325b50e3
5
+ SHA512:
6
+ metadata.gz: 64d932c5cba39505b85a113aff2e225f3f9d5dc6483d8df584462eb854a78945bb9270e20eeea50d48962ade0363789e9725bf6d535efef47d960e79e057421e
7
+ data.tar.gz: 6ffa2b9b8b532a98f99a4eb3a6a07fdced096ed92f709348084cb8c9fb1c2a9f30995ae077286e553e7b1893201eef6f70adf17bdfb35b99b42415ffd0804d27
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ tixriss
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - '2.0.0'
4
+ - '2.1.0'
5
+ cache: bundler
6
+ script:
7
+ - bundle exec rake test
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tixriss.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Carsten Zimmermann
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Tixriss [![Build Status](https://travis-ci.org/Absolventa/tixriss.svg?branch=master)](https://travis-ci.org/Absolventa/tixriss)
2
+
3
+ Tixriss is a simple Ruby library and command line interface to access Sistrix' links.list API.
4
+
5
+ ## Installation
6
+
7
+ If you have a working Ruby installation you can install with:
8
+
9
+ $ gem install tixriss
10
+
11
+ In the rare event that you would like to use the underlying
12
+ Ruby classes in your application, add this to your Gemfile:
13
+
14
+ ```ruby
15
+ gem 'tixriss'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ ## Usage
23
+
24
+ Retrieve XML data and transform output to HTML:
25
+
26
+ ```shell
27
+ tixriss --key <your api key> --domain <reqested domain with link data> --file report.html
28
+ ```
29
+
30
+ To get a full list of available CLI options, type:
31
+
32
+ ```shell
33
+ tixriss --help
34
+ ```
35
+
36
+ ## Changelog
37
+
38
+ ### HEAD (not yet released)
39
+
40
+ ### v0.1.0
41
+ * Initial working prototype
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( https://github.com/Absolventa/tixriss/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "spec"
7
+ t.test_files = FileList['spec/*_spec.rb']
8
+ end
9
+
10
+ task spec: :test
11
+ task default: :test
data/bin/tisriss ADDED
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'tixriss'
5
+
6
+ options = {}
7
+ option_parser = OptionParser.new { |opts|
8
+ opts.banner = "Usage: tisriss [options]"
9
+
10
+ opts.separator ""
11
+ opts.separator "Mandatory options:"
12
+
13
+ opts.on("-d", "--domain DOMAIN", "The requested domain name to get link data for") do |domain|
14
+ options[:domain] = domain
15
+ end
16
+
17
+ opts.on("-k", "--key KEY", "Your Sistrix API key") do |key|
18
+ options[:apikey] = key
19
+ end
20
+
21
+ opts.separator ""
22
+ opts.separator "Other options:"
23
+
24
+ opts.on("-f", "--file OUTPUTFILE", "Location for the generated report (Default: STDOUT)") do |file|
25
+ options[:file] = file.strip
26
+ end
27
+
28
+ opts.on("-i", "--input INPUTFILE", "Use INPUTFILE instead of making an API call") do |file|
29
+ options[:input] = file.strip
30
+ end
31
+
32
+ opts.on("-r", "--save-raw FILENAME", "Save API's XML response in FILENAME") do |file|
33
+ options[:source] = file.strip
34
+ end
35
+
36
+ opts.on_tail("-h", "--help", "Show this help message") do
37
+ puts opts
38
+ end
39
+ }
40
+ option_parser.parse!
41
+
42
+ input = if filename = options[:input]
43
+ File.read(filename)
44
+ end
45
+
46
+ if !input && options[:domain] && options[:apikey]
47
+ request = Tixriss::Request.new(domain: options[:domain], key: options[:apikey])
48
+ input = request.get
49
+ end
50
+
51
+ unless input
52
+ puts option_parser
53
+ exit 1
54
+ end
55
+
56
+ File.open(options[:source], 'w+'){ |f| f.write input } if options[:source]
57
+
58
+ transformer = Tixriss::Transformer.new(input)
59
+
60
+ if filename = options[:file]
61
+ File.open(filename, 'w+') { |f| f.write transformer.output }
62
+ else
63
+ STDOUT.puts transformer.output
64
+ end
65
+
@@ -0,0 +1,25 @@
1
+ module Tixriss
2
+ class Request
3
+ attr_reader :domain, :key
4
+
5
+ def initialize(domain: nil, key: nil)
6
+ @domain, @key = domain, key
7
+ end
8
+
9
+ def response
10
+ @response ||= get
11
+ end
12
+
13
+ def get
14
+ Net::HTTP.get uri
15
+ end
16
+
17
+ def uri
18
+ @uri ||= URI("http://api.sistrix.net/links.list?#{parameters}")
19
+ end
20
+
21
+ def parameters
22
+ "api_key=#{key}&domain=#{domain}"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,83 @@
1
+ module Tixriss
2
+ class Transformer
3
+
4
+ class HTML < Struct.new(:xml)
5
+ def to_s
6
+ [header, body, footer].join "\n"
7
+ end
8
+
9
+ def rows
10
+ links.map do |row|
11
+ data = row.map { |cell| "<td>#{cell}</td>" }.join
12
+ "<tr>#{data}</tr>"
13
+ end
14
+ end
15
+
16
+ def links
17
+ rows = document.xpath('//response/answer/link').map(&:to_s)
18
+ rows.map do |row|
19
+ node = Nokogiri::XML(row)
20
+ url_from = node.xpath('//@url.from')
21
+ url_to = node.xpath('//@url.to')
22
+ text = node.xpath('//@text')
23
+
24
+ [url_from, url_to, text]
25
+ end
26
+ end
27
+
28
+ def document
29
+ @document ||= Nokogiri::XML(xml)
30
+ end
31
+
32
+ def body
33
+ <<-EOBODY
34
+ <body>
35
+ <table class="table table-striped">
36
+ <thead>
37
+ <tr>
38
+ <th>From</th>
39
+ <th>To</th>
40
+ <th>Text</th>
41
+ </tr>
42
+ </thead>
43
+ <tbody>
44
+ #{rows.join("\n")}
45
+ </tbody>
46
+ </table>
47
+ </body>
48
+ EOBODY
49
+ end
50
+
51
+ def header
52
+ <<-EOHEADER
53
+ <html>
54
+ <head>
55
+ <title>Tixriss Report</title>
56
+ <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css" rel="stylesheet"/>
57
+ </head>
58
+ EOHEADER
59
+ end
60
+
61
+ def footer
62
+ '</html>'
63
+ end
64
+ end
65
+
66
+ attr_reader :input
67
+
68
+ def initialize(input)
69
+ @input = input
70
+ end
71
+
72
+ def output
73
+ HTML.new(input).to_s
74
+ end
75
+
76
+ private
77
+
78
+ def output_file
79
+ @output_file ||= File.new(output, 'w+')
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,3 @@
1
+ module Tixriss
2
+ VERSION = "0.1.0"
3
+ end
data/lib/tixriss.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "tixriss/version"
2
+ require 'nokogiri'
3
+
4
+ module Tixriss
5
+ autoload :Request, 'tixriss/request'
6
+ autoload :Transformer, 'tixriss/transformer'
7
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ require 'open3'
3
+
4
+ describe 'the command line interface' do
5
+ let(:inputfile) { File.join File.dirname(File.expand_path(__FILE__)), 'response.xml' }
6
+ let(:response) { File.read(inputfile) }
7
+
8
+ before do
9
+ stub_request(:get, "http://api.sistrix.net/*").to_return(body: response)
10
+ end
11
+
12
+ context 'called with insuffient arguments' do
13
+ it 'displays usage information' do
14
+ output, status = run_cli
15
+ status.wont_equal 0
16
+ output.must_match(/Usage/)
17
+ end
18
+ end
19
+
20
+ context 'with persisted input' do
21
+ it 'transforms the input to stdout' do
22
+ output, status = run_cli(args: ["--input #{inputfile}"])
23
+
24
+ output.must_match(/\A<html>/)
25
+ end
26
+
27
+ it 'writes transformed data to file' do
28
+ outputfile = "./tix.html"
29
+
30
+ output, status = run_cli(args: ["--input #{inputfile}", "--file #{outputfile}"])
31
+
32
+ output.must_equal ''
33
+ File.exists?(outputfile).must_equal true
34
+ File.read(outputfile).must_match(/\A<html>/)
35
+
36
+ FileUtils.rm outputfile
37
+ end
38
+
39
+ it 'allows piping of input data' do
40
+ skip 'Feature not yet implemented'
41
+ end
42
+
43
+ end
44
+
45
+ def run_cli(input = '', args: [])
46
+ output, status = Open3.capture2("./bin/tisriss #{args.join(' ')}", stdin_data: '')
47
+ [output, status.to_i]
48
+ end
49
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tixriss::Request do
4
+ let(:api_key) { SecureRandom.hex 8 }
5
+ let(:domain) { 'absolventa.de' }
6
+ let(:response) { File.read(File.join File.dirname(File.expand_path(__FILE__)), 'response.xml') }
7
+
8
+ subject { Tixriss::Request.new domain: domain, key: api_key }
9
+
10
+ describe 'its constructor' do
11
+ it 'sets the api key' do
12
+ subject = Tixriss::Request.new key: api_key
13
+ subject.key.must_equal api_key
14
+ end
15
+
16
+ it 'sets the domain' do
17
+ subject = Tixriss::Request.new domain: domain
18
+ subject.domain.must_equal domain
19
+ end
20
+ end
21
+
22
+ describe '#get' do
23
+ before do
24
+ get_parameters = "api_key=#{api_key}&domain=#{domain}"
25
+ stub_request(:get, "http://api.sistrix.net/links.list?#{get_parameters}").
26
+ to_return(body: response)
27
+ end
28
+
29
+ it 'returns the xml on success' do
30
+ subject.get.must_equal response
31
+ end
32
+
33
+ it 'caches the result as #response' do
34
+ subject.response.must_equal response
35
+ WebMock.reset! # Makes webmock fail hard if another request is made
36
+ subject.response.must_equal response
37
+ end
38
+
39
+ end
40
+
41
+ end
data/spec/response.xml ADDED
@@ -0,0 +1,9 @@
1
+ <response>
2
+ <api_key />
3
+ <method>links.list</method>
4
+ <answer>
5
+ <link url.from="http://www.google.de/" text="What a job platform!" url.to="http://www.absolventa.de/"/>
6
+ <link url.from="http://www.yahoo.de/" text="Look no further" url.to="http://www.absolventa.de/"/>
7
+ </answer>
8
+ <credits used="2" />
9
+ </response>
@@ -0,0 +1,6 @@
1
+ require 'tixriss'
2
+
3
+ require 'minitest/autorun'
4
+ require 'minitest/pride'
5
+ require 'minitest-spec-context'
6
+ require 'webmock/minitest'
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tixriss::Transformer do
4
+ let(:input) { File.read(File.join File.dirname(File.expand_path(__FILE__)), 'response.xml') }
5
+
6
+ subject { Tixriss::Transformer.new input }
7
+
8
+ describe 'its constructor' do
9
+ it 'sets the input file' do
10
+ subject = Tixriss::Transformer.new input
11
+ subject.input.must_equal input
12
+ end
13
+ end
14
+
15
+ describe '#write' do
16
+ it 'has an html table' do
17
+ html = Nokogiri::HTML(subject.output)
18
+
19
+ html.css('table thead tr').size.must_equal 1
20
+ html.css('table tbody tr').size.must_equal 2
21
+ end
22
+ end
23
+ end
data/tixriss.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tixriss/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tixriss"
8
+ spec.version = Tixriss::VERSION
9
+ spec.authors = ["Carsten Zimmermann"]
10
+ spec.email = ["cz@aegisnet.de"]
11
+ spec.summary = %q{Simple Ruby library and command line interface to access Sistrix' links.list API}
12
+ spec.description = %q{Retrieves links.list data and allows processing/transformation}
13
+ spec.homepage = "https://github.com/Absolventa/tixriss"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '>= 2.0'
22
+
23
+ spec.add_dependency "nokogiri"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "webmock"
28
+ spec.add_development_dependency "minitest", "~> 5.0"
29
+ spec.add_development_dependency "minitest-spec-context"
30
+ spec.add_development_dependency "minitest-implicit-subject"
31
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tixriss
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Carsten Zimmermann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-spec-context
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest-implicit-subject
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Retrieves links.list data and allows processing/transformation
112
+ email:
113
+ - cz@aegisnet.de
114
+ executables:
115
+ - tisriss
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - .ruby-gemset
121
+ - .ruby-version
122
+ - .travis.yml
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/tisriss
128
+ - lib/tixriss.rb
129
+ - lib/tixriss/request.rb
130
+ - lib/tixriss/transformer.rb
131
+ - lib/tixriss/version.rb
132
+ - spec/command_line_spec.rb
133
+ - spec/request_spec.rb
134
+ - spec/response.xml
135
+ - spec/spec_helper.rb
136
+ - spec/transformer_spec.rb
137
+ - tixriss.gemspec
138
+ homepage: https://github.com/Absolventa/tixriss
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '2.0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.2.2
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: Simple Ruby library and command line interface to access Sistrix' links.list
162
+ API
163
+ test_files:
164
+ - spec/command_line_spec.rb
165
+ - spec/request_spec.rb
166
+ - spec/response.xml
167
+ - spec/spec_helper.rb
168
+ - spec/transformer_spec.rb