twoffein-client 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.
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +207 -0
- data/README.md.erb +52 -0
- data/Rakefile +67 -0
- data/VERSION +1 -0
- data/bin/twoffein-client +84 -0
- data/features/step_definitions/twoffein-client_steps.rb +1 -0
- data/features/support/env.rb +16 -0
- data/features/twoffein-client.feature +13 -0
- data/fixtures/vcr_cassettes/cookie.yml +234 -0
- data/fixtures/vcr_cassettes/drink.yml +60 -0
- data/fixtures/vcr_cassettes/drinks.yml +461 -0
- data/fixtures/vcr_cassettes/profile.yml +69 -0
- data/fixtures/vcr_cassettes/tweet.yml +103 -0
- data/lib/twoffein-client.rb +12 -0
- data/lib/twoffein-client/constants.rb +9 -0
- data/lib/twoffein-client/cookie.rb +23 -0
- data/lib/twoffein-client/credentials.rb +5 -0
- data/lib/twoffein-client/drink.rb +43 -0
- data/lib/twoffein-client/drinks.rb +96 -0
- data/lib/twoffein-client/exceptions.rb +15 -0
- data/lib/twoffein-client/http.rb +96 -0
- data/lib/twoffein-client/profile.rb +61 -0
- data/lib/twoffein-client/tweet.rb +31 -0
- data/lib/twoffein-client/util.rb +7 -0
- data/lib/twoffein-client/version.rb +7 -0
- data/spec/constants_spec.rb +11 -0
- data/spec/cookie_spec.rb +25 -0
- data/spec/drink_spec.rb +49 -0
- data/spec/drinks_spec.rb +154 -0
- data/spec/exceptions_spec.rb +14 -0
- data/spec/http_spec.rb +94 -0
- data/spec/profile_spec.rb +58 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/tweet_spec.rb +41 -0
- data/spec/util_spec.rb +20 -0
- data/twoffein-client.gemspec +28 -0
- metadata +245 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.3@twoffein-client --create
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 DSIW
|
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,207 @@
|
|
1
|
+
# Twoffein-Client
|
2
|
+
Client-Version: 1.0.0 | API-Version: 0.2
|
3
|
+
|
4
|
+
This client for [Twoffein](http://twoffein.com/)'s [API](http://twoffein.com/api-faq/).
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'twoffein-client'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install twoffein-client
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```
|
23
|
+
NAME
|
24
|
+
twoffein-client - Client for API 0.2 twoffein.de
|
25
|
+
|
26
|
+
SYNOPSIS
|
27
|
+
twoffein-client [global options] command [command options] [arguments...]
|
28
|
+
|
29
|
+
VERSION
|
30
|
+
1.0.0
|
31
|
+
|
32
|
+
GLOBAL OPTIONS
|
33
|
+
--help - Show this message
|
34
|
+
--version - Show version
|
35
|
+
|
36
|
+
COMMANDS
|
37
|
+
cookie - Give cookie to RECEIVER
|
38
|
+
drinks - List all drinks
|
39
|
+
help - Shows a list of commands or help for one command
|
40
|
+
profile - List the profile, which you have chosen by PROFILE
|
41
|
+
tweet - Tweet your drinking DRINK
|
42
|
+
|
43
|
+
```
|
44
|
+
|
45
|
+
## Examples
|
46
|
+
|
47
|
+
### Drinks
|
48
|
+
|
49
|
+
**Input:**
|
50
|
+
|
51
|
+
twoffein-client drinks
|
52
|
+
|
53
|
+
**Output:**
|
54
|
+
```
|
55
|
+
Drink (key)
|
56
|
+
-------------------------------------------
|
57
|
+
Kaffee (kaffee)
|
58
|
+
Milchkaffee (milchkaffee)
|
59
|
+
Eiskaffee (eiskaffee)
|
60
|
+
Energy Drink (energiedrink)
|
61
|
+
Cola (cola)
|
62
|
+
Cola Light (colalight)
|
63
|
+
Cola Zero (colazero)
|
64
|
+
Cola-Mix (colamix)
|
65
|
+
Cola-Mix Light (colamixlight)
|
66
|
+
Cola-Mix Zero (colamixzero)
|
67
|
+
Bubble Tea (bubbletea)
|
68
|
+
Cherry Cola (cherrycola)
|
69
|
+
Vanilla Cola (vanillacola)
|
70
|
+
Caffé Latte (cafelatte)
|
71
|
+
Caffé au Lait (cafeaulait)
|
72
|
+
Latte Macchiato (lattemacchiato)
|
73
|
+
Espresso Macciato (espressomacciato)
|
74
|
+
Espresso con Panne (espressoconpanne)
|
75
|
+
Flat White (flatwhite)
|
76
|
+
Caffé Breve (caffebreve)
|
77
|
+
Caffé Mocha (caffemocha)
|
78
|
+
Americano (americano)
|
79
|
+
Melange (melange)
|
80
|
+
Red Eye (redeye)
|
81
|
+
Tee (tee)
|
82
|
+
Eistee (eistee)
|
83
|
+
Kakao (kakao)
|
84
|
+
Mate (mate)
|
85
|
+
Espresso (espresso)
|
86
|
+
Cappuccino (cappuccino)
|
87
|
+
Vannillochino (vannillochino)
|
88
|
+
Instantkaffee (instantkaffee)
|
89
|
+
Mokka (mokka)
|
90
|
+
Chai-Latte (chailatte)
|
91
|
+
Grünen Tee (guenertee)
|
92
|
+
Schwarztee (schwarztee)
|
93
|
+
1337MATE (leetmate)
|
94
|
+
Club-Mate (clubmate)
|
95
|
+
Club-Mate Cola (clubmatecola)
|
96
|
+
ICE-Tea KRAFTSTOFF (kraftstoff)
|
97
|
+
Premium-Cola (premiumcola)
|
98
|
+
Dr Pepper (drpepper)
|
99
|
+
Vita Cola (vitacola)
|
100
|
+
Vita Cola Mix (vitacolamix)
|
101
|
+
Vita Cola Pur (vitacolapur)
|
102
|
+
Schokocino (schokocino)
|
103
|
+
afri cola (africola)
|
104
|
+
afri sugarfree (afrisugarfree)
|
105
|
+
afri power (afripower)
|
106
|
+
fritz-kola (fritzkola)
|
107
|
+
fritz-kola stevia (fritzkolastevia)
|
108
|
+
fritz-kola zuckerfrei (fritzkolazuckerfrei)
|
109
|
+
mischmasch (mischmasch)
|
110
|
+
Haji Cola (hajicola)
|
111
|
+
KILLERFISH Hot Energy (killerfishhotenergy)
|
112
|
+
Café Frappé (cafefrappe)
|
113
|
+
Energy Shot (energyshot)
|
114
|
+
Wasser (wasser)
|
115
|
+
Mineralwasser (mineralwasser)
|
116
|
+
Apfelsaft (apfelsaft)
|
117
|
+
Orangensaft (orangensaft)
|
118
|
+
Milch (milch)
|
119
|
+
Sojamilch (sojamilch)
|
120
|
+
Orangenlimonade (orangenlimonade)
|
121
|
+
Zitronenlimonade (zitronenlimonade)
|
122
|
+
Kräuterlimonade (kraeuterlimonade)
|
123
|
+
Apfelsaftschorle (apfelsaftschorle)
|
124
|
+
Ginger Ale (gingerale)
|
125
|
+
Tonic Water (tonicwater)
|
126
|
+
Bitter Lemon (bitterlemon)
|
127
|
+
Bananensaft (bananensaft)
|
128
|
+
Traubensaft (traubensaft)
|
129
|
+
Milchshake (milchshake)
|
130
|
+
Joghurtdrink (joghurtdrink)
|
131
|
+
Smoothie (smoothie)
|
132
|
+
Espresso Doppio (espressodoppio)
|
133
|
+
Fassbrause (fassbrause)
|
134
|
+
Ayran (ayran)
|
135
|
+
Flora Power (florapower)
|
136
|
+
VOLT Cola (voltcola)
|
137
|
+
COFAIN 699 (cofain669)
|
138
|
+
Erdbeersaft (erdbeersaft)
|
139
|
+
KiBa (kiba)
|
140
|
+
Müllermilch (muellermilch)
|
141
|
+
```
|
142
|
+
|
143
|
+
### Drinks (filtered)
|
144
|
+
|
145
|
+
**Input:**
|
146
|
+
|
147
|
+
twoffein-client drinks --grep club
|
148
|
+
|
149
|
+
**Output:**
|
150
|
+
```
|
151
|
+
Drink (key)
|
152
|
+
------------------------------------
|
153
|
+
Club-Mate (clubmate)
|
154
|
+
Club-Mate Cola (clubmatecola)
|
155
|
+
```
|
156
|
+
|
157
|
+
### Profile
|
158
|
+
|
159
|
+
**Input:**
|
160
|
+
|
161
|
+
twoffein-client profile
|
162
|
+
|
163
|
+
**Output:**
|
164
|
+
```
|
165
|
+
Quest: Blitzlicht
|
166
|
+
Drink: Club-Mate
|
167
|
+
Rank: 75
|
168
|
+
Rank Title: Kaffeekännchen
|
169
|
+
Drunken: 12
|
170
|
+
Bluttwoffeinkonzentration: 1%
|
171
|
+
First Login: 2012-07-08 13:36
|
172
|
+
Screen Name: DSIW
|
173
|
+
```
|
174
|
+
|
175
|
+
### Cookie
|
176
|
+
|
177
|
+
**Input:**
|
178
|
+
|
179
|
+
twoffein-client cookie DSIW
|
180
|
+
|
181
|
+
**Output:**
|
182
|
+
```
|
183
|
+
Lol.
|
184
|
+
```
|
185
|
+
|
186
|
+
_Notice: You can't send yourself a cookie._
|
187
|
+
|
188
|
+
### Tweet
|
189
|
+
|
190
|
+
**Input:**
|
191
|
+
|
192
|
+
twoffein-client tweet clubmate
|
193
|
+
|
194
|
+
**Output:**
|
195
|
+
```
|
196
|
+
Ich trinke gerade Club-Mate.
|
197
|
+
Info: Youre Tweet has been tweeted. Thanks.
|
198
|
+
Drinks today: 1
|
199
|
+
```
|
200
|
+
|
201
|
+
## Contributing
|
202
|
+
|
203
|
+
1. Fork it
|
204
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
205
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
206
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
207
|
+
5. Create new Pull Request
|
data/README.md.erb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Twoffein-Client
|
2
|
+
Client-Version: <%= require File.absolute_path("lib/twoffein-client/version.rb", __FILE__); Twoffein::Client::VERSION %> | API-Version: <%= require File.absolute_path("lib/twoffein-client/version.rb", __FILE__); Twoffein::Server::VERSION %>
|
3
|
+
|
4
|
+
This client for [Twoffein](http://twoffein.com/)'s [API](http://twoffein.com/api-faq/).
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'twoffein-client'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install twoffein-client
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```
|
23
|
+
<%= %x[bundle exec bin/twoffein-client --help] %>
|
24
|
+
```
|
25
|
+
|
26
|
+
## Examples
|
27
|
+
<%
|
28
|
+
def example(title, command);
|
29
|
+
title = "### #{title}"
|
30
|
+
input = "**Input:**\n\n #{command.gsub("bundle exec bin/",'')}"
|
31
|
+
output = "**Output:**\n```\n#{%x[#{command}]}```"
|
32
|
+
[title, input, output].join("\n\n")
|
33
|
+
end
|
34
|
+
%>
|
35
|
+
|
36
|
+
<%= example "Drinks", "bundle exec bin/twoffein-client drinks" %>
|
37
|
+
|
38
|
+
<%= example "Drinks (filtered)", "bundle exec bin/twoffein-client drinks --grep club" %>
|
39
|
+
|
40
|
+
<%= example "Profile", "bundle exec bin/twoffein-client profile" %>
|
41
|
+
|
42
|
+
<%= example "Cookie", "bundle exec bin/twoffein-client cookie DSIW" %>
|
43
|
+
|
44
|
+
<%= example "Tweet", "bundle exec bin/twoffein-client tweet clubmate" %>
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
require 'rake/clean'
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
require 'cucumber'
|
7
|
+
require 'cucumber/rake/task'
|
8
|
+
gem 'rdoc' # we need the installed RDoc gem, not the system one
|
9
|
+
require 'rdoc/task'
|
10
|
+
|
11
|
+
require 'pathname'
|
12
|
+
|
13
|
+
require File.expand_path('../lib/twoffein-client/version', __FILE__)
|
14
|
+
|
15
|
+
include Rake::DSL
|
16
|
+
|
17
|
+
Bundler::GemHelper.install_tasks
|
18
|
+
|
19
|
+
RSpec::Core::RakeTask.new do |t|
|
20
|
+
# Put spec opts in a file named .rspec in root
|
21
|
+
end
|
22
|
+
|
23
|
+
CUKE_RESULTS = 'results.html'
|
24
|
+
CLEAN << CUKE_RESULTS
|
25
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
26
|
+
t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
|
27
|
+
t.fork = false
|
28
|
+
end
|
29
|
+
|
30
|
+
Rake::RDocTask.new do |rd|
|
31
|
+
#rd.main = "README.rdoc"
|
32
|
+
rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rake/version_task'
|
36
|
+
Rake::VersionTask.new
|
37
|
+
|
38
|
+
task :default => [:spec,:features]
|
39
|
+
|
40
|
+
module Erb
|
41
|
+
require 'erb'
|
42
|
+
|
43
|
+
def rm_basename_ext file, extension
|
44
|
+
path = Pathname.new(file)
|
45
|
+
path.basename.sub(/\.#{extension}$/, '').to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
def target_of file
|
49
|
+
rm_basename_ext(file, "erb")
|
50
|
+
end
|
51
|
+
|
52
|
+
def generate_file file, options={}
|
53
|
+
target = target_of file
|
54
|
+
puts "generating #{target}"
|
55
|
+
return if options[:noop]
|
56
|
+
|
57
|
+
File.open(target, 'w') do |new_file|
|
58
|
+
new_file.write ERB.new(File.read(file)).result(binding)
|
59
|
+
end
|
60
|
+
rescue Interrupt
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "Generate README.md"
|
65
|
+
task :gen_readme do
|
66
|
+
Erb::generate_file "README.md.erb"
|
67
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/twoffein-client
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'twoffein-client'
|
4
|
+
require 'gli'
|
5
|
+
|
6
|
+
include Twoffein
|
7
|
+
include GLI::App
|
8
|
+
|
9
|
+
DEBUG = $DEBUG
|
10
|
+
|
11
|
+
program_desc "Client for API #{Server::VERSION} twoffein.de"
|
12
|
+
|
13
|
+
desc "Show version"
|
14
|
+
version Client::VERSION
|
15
|
+
|
16
|
+
desc 'List the profile, which you have chosen by PROFILE'
|
17
|
+
arg_name 'Name of profile which will be shown'
|
18
|
+
command :profile do |c|
|
19
|
+
#c.desc "Grep all profiles"
|
20
|
+
#c.flag :grep
|
21
|
+
|
22
|
+
c.action do |global_options,options,args|
|
23
|
+
profile = args.first
|
24
|
+
#if options[:grep]
|
25
|
+
#puts Profiles.search(/#{options["grep"]}/i)
|
26
|
+
#else
|
27
|
+
puts Profile.get profile
|
28
|
+
#end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "List all drinks"
|
33
|
+
arg_name "Describe arguments to drinks here"
|
34
|
+
command :drinks do |c|
|
35
|
+
c.desc "Grep all drinks"
|
36
|
+
c.flag :grep
|
37
|
+
|
38
|
+
c.action do |global_options,options,args|
|
39
|
+
if options[:grep]
|
40
|
+
puts Drinks.search(/#{options[:grep]}/i)
|
41
|
+
else
|
42
|
+
puts Drinks.new
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
desc 'Tweet your drinking DRINK'
|
48
|
+
arg_name 'key_of_drink (see command "drinks")'
|
49
|
+
command :tweet do |c|
|
50
|
+
c.desc "Drink with somebody"
|
51
|
+
c.flag :with
|
52
|
+
|
53
|
+
c.action do |global_options,options,args|
|
54
|
+
help_now!('DRINK is required') if args.empty?
|
55
|
+
drink = args.first
|
56
|
+
tweet = Tweet.new(drink, options[:with])
|
57
|
+
puts tweet.to_s
|
58
|
+
begin
|
59
|
+
info = tweet.publish unless DEBUG
|
60
|
+
puts 'Info: ' + info[:info] unless info.nil?
|
61
|
+
puts 'Drinks today: ' + info[:tweets].to_s if info && !info[:tweets].nil?
|
62
|
+
rescue Twoffein::Error => e
|
63
|
+
puts e.message
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
desc 'Give cookie to RECEIVER'
|
69
|
+
arg_name 'Receiver receives your cookie'
|
70
|
+
command :cookie do |c|
|
71
|
+
c.action do |global_options,options,args|
|
72
|
+
help_now!('RECEIVER is required') if args.empty?
|
73
|
+
receiver = args.first
|
74
|
+
cookie = Cookie.new(receiver)
|
75
|
+
begin
|
76
|
+
info = cookie.send unless DEBUG
|
77
|
+
puts 'Info: ' + info[:info] unless info.nil?
|
78
|
+
rescue Twoffein::Error => e
|
79
|
+
puts e.message
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
exit run(ARGV)
|