velibe 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2961ad36ef9de68b90ad01c7f57f920e49f74ac
4
- data.tar.gz: 12ec6625b623911df17ec26639031044d3fa3a6b
3
+ metadata.gz: 77f7f5b9baaec5d5a804ff15b0a344df335be84b
4
+ data.tar.gz: d2bfd4d5d77d941a68033ee17cf63b98faac404d
5
5
  SHA512:
6
- metadata.gz: fb69057de4323e003c95cfc3aaa5e20a6b0f34752a5ad83f5824f15e5416853035e457267d5727cff47013db528bbc44b5c36c11fe06aadd635e51f481d5620f
7
- data.tar.gz: 742e5306b09c31d5cd62517cc55eb7b25579858bd57ea47a1a72eaeecff35947ec3def01b59961f60eec8dd937da49df10f9c7b6485cccd1aa659fa1cf7bdb65
6
+ metadata.gz: a721e24aa50e2928b6fc60296142fa6c79d2aeaf653760f116d8307f1ecd3672c7ed1a8555bb90d32bbd84910e3968191eea59587e56507350ca94097e388075
7
+ data.tar.gz: 0781a73c8ae7f37ce033996c5bcdeaf1e4226feba15bb8c8bc99eeb90119d9af5ddb2e0199f4c92f9a36ad428caa47bc7c03765590ebfdc77d0aa424d1afdc14
@@ -1,4 +1,7 @@
1
1
  language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+
2
5
  rvm:
3
6
  - 2.0.0
4
7
  - 2.1
@@ -5,8 +5,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
6
  ## [Unreleased][unreleased]
7
7
 
8
- ## [0.1.0] - 2015-11-18
8
+ ## [0.2.0] - 2015-11-29
9
9
  ### Added
10
+ - favorites storage with a `.velibe.yaml`
11
+ - commands to *display*, *add* and *reset* favorites
12
+ - CI setup (see badge on README)
13
+
14
+ ## [0.1.0] - 2015-11-18
10
15
  ### Changed
11
16
  - Token must be specified with the `VELIBE_TOKEN` environment variable.
12
17
 
@@ -22,7 +27,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
22
27
  ## [0.0.1] - 2015-07-04
23
28
  - Initial Release
24
29
 
25
- [unreleased]: https://github.com/AdrieanKhisbe/velibe/compare/v0.1.0...HEAD
30
+ [unreleased]: https://github.com/AdrieanKhisbe/velibe/compare/v0.2.0...HEAD
31
+ [0.2.0]: https://github.com/AdrieanKhisbe/velibe/compare/v0.1.0...v0.2.0
26
32
  [0.1.0]: https://github.com/AdrieanKhisbe/velibe/compare/v0.0.2...v0.1.0
27
33
  [0.0.2]: https://github.com/AdrieanKhisbe/velibe/compare/v0.0.1...v0.0.2
28
34
  [0.0.1]: https://github.com/AdrieanKhisbe/velibe/compare/02a6045....v0.10
@@ -0,0 +1,20 @@
1
+ # Contributing
2
+
3
+ ## Issue Reporting
4
+
5
+ Issue report are more than welcome, but to be efficiently handle you should
6
+ include your ruby version and a stacktrace.
7
+
8
+ ## Proposal of Features
9
+ If there is a feature you would like to be added, just suggest it.
10
+
11
+ If you want to implement it yourself, I stringly recommand you to talk
12
+ about it first, posting a issue describing the intentinded feature,
13
+ and the main ideas about how you would implement it.
14
+
15
+ ## Development
16
+ 1. Fork it ( https://github.com/[my-github-username]/VeLibe/fork )
17
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
18
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
19
+ 4. Push to the branch (`git push origin my-new-feature`)
20
+ 5. Create a new Pull Request
data/README.md CHANGED
@@ -22,6 +22,8 @@ Just install the gem, and you'll have access to this wonderful tool :D
22
22
  The cli relies on the JcDecaux API. You need an api token to be able to use it.
23
23
  You can see the official site to get one [there]
24
24
  (https://developer.jcdecaux.com/#/opendata/vls?page=dynamic).
25
+ You'll need to create an [account](https://developer.jcdecaux.com/#/account),
26
+ and an acces token will be then granted
25
27
 
26
28
  This token is to be stored in the `VELIBE_TOKEN` variable environment.
27
29
 
data/bin/velibe CHANGED
@@ -1,10 +1,29 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
- ## My Velib Querier
3
+ ## My Velib Querrier
4
4
 
5
5
  require 'velibe'
6
6
 
7
- ## Main
8
- Velibe.print_stations(ARGV)
7
+ case ARGV[0]
8
+ when /f(av(orite)?)?$/
9
+ # handle favorites
10
+ case ARGV[1]
11
+ when /a(dd)?/
12
+ stations = ARGV[2..-1]
13
+ # TODO: check if all number
14
+ Velibe.add_favorite(stations)
15
+ when /setup|reset/
16
+ force = ARGV[2..-1].any? { |s| /-(f|-force)/ }
17
+ if Velibe.reset_favorites(force)
18
+ puts 'Favorites Stations were reset'
19
+ else
20
+ puts 'Favorites not empty, you need to add --force/-f flag if you really want to reset'
21
+ end
22
+ else
23
+ Velibe.print_favorites
24
+ end
9
25
 
10
- # garder sta à gauche du chevron?
26
+ else
27
+ # TODO: check if all number
28
+ Velibe.print_stations(ARGV)
29
+ end
@@ -4,17 +4,21 @@ require 'velibe/api_velib'
4
4
  require 'velibe/station_status'
5
5
  require 'velibe/db/database'
6
6
  require 'velibe/db/models'
7
+ require 'velibe/db/kv_store'
7
8
 
8
9
  module Velibe
9
10
 
10
11
  # Default values > Move
11
- Favorites = [10035, 19003, 19004, 10031]
12
+ tmp_fav = KvStore.favorite_stations
13
+ Favorites = tmp_fav.nil? ? [10035, 19003, 19004, 10031] : tmp_fav
12
14
 
13
15
  # TODO: try catch network exception
14
16
  # TODO lazy singleton!!
15
17
 
18
+ # TODO extract cli class, and include!
16
19
  # §maybe: class CLI
17
20
 
21
+
18
22
  def self.print_stations(stations)
19
23
  stations = Favorites if stations.empty? or !stations
20
24
  puts "Velibe >> Stations #{stations.join(', ')}:"
@@ -26,6 +30,26 @@ module Velibe
26
30
  puts "Velibe >> Stations #{stations.join(', ')}:"
27
31
  ApiVelib.get_stations(stations) { |station| StationStatus.print_from_json(station, ' > ') }
28
32
  end
33
+
29
34
  # TODO: Bench both?
30
35
 
36
+
37
+ def self.print_favorites
38
+ if Favorites.empty?
39
+ puts 'No favorites so far, you can add some with `velibe favorite add <your> <number>`.'
40
+ else
41
+ puts "Favorites Stations: #{Favorites.join(', ')}"
42
+ # TODO: print details with db
43
+ end
44
+ end
45
+
46
+ def self.reset_favorites(force = false)
47
+ KvStore.reset_favorite_stations if force or KvStore.favorite_stations.empty?
48
+ end
49
+
50
+ def self.add_favorite(stations)
51
+ KvStore.add_favorite_station(*stations)
52
+ end
53
+
54
+
31
55
  end
@@ -5,10 +5,10 @@ require 'json'
5
5
  module Velibe
6
6
  class ApiVelib
7
7
 
8
- API_KEY = ENV['VELIBE_TOKEN'] || raise('No token provided')
8
+ API_KEY = ENV['VELIBE_TOKEN'] || KvStore.token || raise('No token provided')
9
9
 
10
10
  API_HOST = 'https://api.jcdecaux.com'
11
- API_PARAM= { contract: 'paris', apiKey: API_KEY }
11
+ API_PARAM = { contract: 'paris', apiKey: API_KEY }
12
12
  API_BASE_URI = '/vls/v1/stations'
13
13
 
14
14
  def self.get_station(station_number)
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'moneta'
3
+
4
+ module Velibe
5
+
6
+ module KvStore
7
+ NAME = '~/.velib.yaml' # TODO: more generic
8
+ PATH = Pathname.new(NAME).expand_path
9
+ DB = Moneta.new(:YAML, file: PATH)
10
+
11
+ FAV_KEY = 'favorites'
12
+
13
+ def self.token
14
+ DB['token']
15
+ end
16
+
17
+ def self.reset_favorite_stations
18
+ DB[FAV_KEY] = []
19
+ end
20
+
21
+ def self.favorite_stations
22
+ DB[FAV_KEY]
23
+ end
24
+
25
+ def self.add_favorite_station(*stations)
26
+ fav = DB[FAV_KEY]
27
+ # TODO: handle setup
28
+ # TODO: check existing station
29
+ stations.each { |station| fav.push(station) unless fav.include?(station) }
30
+ DB[FAV_KEY] = fav
31
+ end
32
+
33
+ end
34
+ end
@@ -1,3 +1,3 @@
1
1
  module Velibe
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = 'velibe'
8
8
  spec.version = Velibe::VERSION
9
9
  spec.authors = ['Adriean Khisbe']
10
- spec.email = ["adriean.khisbe@live.fr"]
10
+ spec.email = ['adriean.khisbe@live.fr']
11
11
  spec.summary = %q{Small Velib Utility}
12
12
  spec.description = %q{Wrapper for Velib api, for no-fuss cycling}
13
13
  spec.homepage = 'https://github.com/AdrieanKhisbe/velibe'
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'http', '~> 0.9.8'
22
22
  spec.add_dependency 'sqlite3'
23
23
  spec.add_dependency 'activerecord'
24
+ spec.add_dependency 'moneta', '~> 0.8'
24
25
 
25
26
  spec.add_development_dependency 'bundler', '~> 1.6'
26
27
  spec.add_development_dependency 'rake'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: velibe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adriean Khisbe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-19 00:00:00.000000000 Z
11
+ date: 2015-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: moneta
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +178,7 @@ files:
164
178
  - ".rubocop.yml"
165
179
  - ".travis.yml"
166
180
  - CHANGELOG.md
181
+ - CONTRIBUTING.md
167
182
  - Gemfile
168
183
  - LICENSE.txt
169
184
  - README.md
@@ -174,6 +189,7 @@ files:
174
189
  - lib/velibe.rb
175
190
  - lib/velibe/api_velib.rb
176
191
  - lib/velibe/db/database.rb
192
+ - lib/velibe/db/kv_store.rb
177
193
  - lib/velibe/db/models.rb
178
194
  - lib/velibe/station_status.rb
179
195
  - lib/velibe/version.rb