bistip 0.0.4
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 +3 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +47 -0
- data/Rakefile +2 -0
- data/bistip.gemspec +28 -0
- data/lib/bistip.rb +50 -0
- data/lib/bistip/version.rb +3 -0
- metadata +91 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Agung Prasetyo
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
= bistip
|
2
|
+
|
3
|
+
Get tip for your trip! A full-stack Bistip.com API wrapper in Ruby.
|
4
|
+
|
5
|
+
== Instalation
|
6
|
+
|
7
|
+
gem install bistip
|
8
|
+
|
9
|
+
== Features:
|
10
|
+
|
11
|
+
* Easy to fetch data from bistip API with searching trips and searching wanted post function, that specified by some parameter, like <b>:from</b> and <b>:to</b>, optional parameter like <b>:page</b> and <b>:per_page</b> to control pagination
|
12
|
+
* (Optional) You can control result number with pagination using <b>:page</b> and <b>:per_page</b> properties. By default :page value is 1 and :per_page value is 10
|
13
|
+
|
14
|
+
|
15
|
+
== Examples
|
16
|
+
|
17
|
+
Now bistip ruby gem supports all objects listed here: http://www.bistip.com/api
|
18
|
+
|
19
|
+
=== GET
|
20
|
+
==== Searching for trips or wanted_post
|
21
|
+
|
22
|
+
# trips from jakarta to osaka
|
23
|
+
Bistip::trips({ :from => 'jakarta', :to => 'Osaka'})
|
24
|
+
|
25
|
+
# trips from yogyakarta
|
26
|
+
Bistip::trips({ :from => 'yogyakarta' })
|
27
|
+
|
28
|
+
# wanted post from jakarta with pagination (optional, default
|
29
|
+
Bistip::seeks({ :from => 'jakarta', :page => 1, :per_page => 20})
|
30
|
+
|
31
|
+
|
32
|
+
Every method will generate array of hash where the array element would have structure like :
|
33
|
+
|
34
|
+
trip: {
|
35
|
+
origin_location: "city, country",
|
36
|
+
notes: "lorem ipsum dolor sit amet",
|
37
|
+
period: null,
|
38
|
+
username: "foo",
|
39
|
+
arrival_date_medium_format: "2011-10-10",
|
40
|
+
departure_date_medium_format: "2011-10-09",
|
41
|
+
id: 742,
|
42
|
+
day: null,
|
43
|
+
routine: false,
|
44
|
+
destination_location: "Jakarta, Indonesia"
|
45
|
+
}
|
46
|
+
|
47
|
+
And will generate an empty array if no trips/seeks found in bistip specified by parameter
|
data/Rakefile
ADDED
data/bistip.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "bistip/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "bistip"
|
7
|
+
s.version = Bistip::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Agung Prasetyo"]
|
10
|
+
s.email = ["brain64bit@gmail.com"]
|
11
|
+
s.extra_rdoc_files = ["MIT-LICENSE","README.rdoc"]
|
12
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
13
|
+
s.homepage = "http://kav1nsky.wordpress.com"
|
14
|
+
s.summary = %q{A Ruby wrapper based on Bistip.com API}
|
15
|
+
s.description = %q{Ruby wrapper that consume Bistip.com REST API, for searching trips and searching wanted post specified by some parameter}
|
16
|
+
s.date = Time.now.utc.strftime("%A, %d% %B %Y")
|
17
|
+
s.rubyforge_project = "bistip"
|
18
|
+
|
19
|
+
s.add_dependency "httparty", "= 0.7.8"
|
20
|
+
|
21
|
+
s.post_install_message = "Get tip for your trip"
|
22
|
+
|
23
|
+
s.files = `git ls-files`.split("\n")
|
24
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
25
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
26
|
+
s.require_paths = ["lib"]
|
27
|
+
|
28
|
+
end
|
data/lib/bistip.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module Bistip
|
4
|
+
include HTTParty
|
5
|
+
# Your code goes here...
|
6
|
+
|
7
|
+
base_uri 'http://www.bistip.com'
|
8
|
+
|
9
|
+
API_VERSION = '/api/v1'
|
10
|
+
SEARCH_TRIP = '/trips.json'
|
11
|
+
SEARCH_SEEK = '/seeks.json'
|
12
|
+
DEFAULT_PER_PAGE = 10
|
13
|
+
DEFAULT_PAGE = 1
|
14
|
+
|
15
|
+
def self.trips(params={})
|
16
|
+
check_params(params)
|
17
|
+
from = params[:from] if params[:from]
|
18
|
+
to = params[:to] if params[:to]
|
19
|
+
per_page = params[:per_page].nil? ? DEFAULT_PER_PAGE : params[:per_page]
|
20
|
+
page = params[:page].nil? ? DEFAULT_PAGE : params[:page]
|
21
|
+
|
22
|
+
result = get("#{API_VERSION+SEARCH_TRIP}?from=#{from}&to=#{to}&page=#{page}&per_page=#{per_page}")
|
23
|
+
result = result.first.include?("exception") ? Array.new : result
|
24
|
+
return result
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.seeks(params={})
|
28
|
+
check_params(params)
|
29
|
+
from = params[:from] if params[:from]
|
30
|
+
to = params[:to] if params[:to]
|
31
|
+
per_page = params[:per_page].nil? ? DEFAULT_PER_PAGE : params[:per_page]
|
32
|
+
page = params[:page].nil? ? DEFAULT_PAGE : params[:page]
|
33
|
+
|
34
|
+
result = get("#{API_VERSION+SEARCH_SEEK}?from=#{from}&to=#{to}&page=#{page}&per_page=#{per_page}")
|
35
|
+
result = result.first.include?("exception") ? Array.new : result
|
36
|
+
return result
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def self.check_params(params)
|
42
|
+
raise ArgumentError, 'parameters must be a hash' unless params.is_a?(Hash)
|
43
|
+
raise ArgumentError, 'parameters can not be empty' unless !params.empty?
|
44
|
+
raise ArgumentError, 'parameters should contain :from and/or :to properties' unless params.keys.include?(:from) or params.keys.include?(:to)
|
45
|
+
|
46
|
+
raise ArgumentError, ':page must be an integer' unless params[:page].is_a?(Integer) if params[:page]
|
47
|
+
raise ArgumentError, ':per_page must be an integer' unless params[:per_page].is_a?(Integer) if params[:per_page]
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bistip
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Agung Prasetyo
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-19 00:00:00 +07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: httparty
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 19
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 7
|
33
|
+
- 8
|
34
|
+
version: 0.7.8
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Ruby wrapper that consume Bistip.com REST API, for searching trips and searching wanted post specified by some parameter
|
38
|
+
email:
|
39
|
+
- brain64bit@gmail.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- MIT-LICENSE
|
46
|
+
- README.rdoc
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- Rakefile
|
51
|
+
- bistip.gemspec
|
52
|
+
- lib/bistip.rb
|
53
|
+
- lib/bistip/version.rb
|
54
|
+
- MIT-LICENSE
|
55
|
+
- README.rdoc
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: http://kav1nsky.wordpress.com
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message: Get tip for your trip
|
61
|
+
rdoc_options:
|
62
|
+
- --charset=UTF-8
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project: bistip
|
86
|
+
rubygems_version: 1.3.7
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: A Ruby wrapper based on Bistip.com API
|
90
|
+
test_files: []
|
91
|
+
|