Class: ParseAPI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/parseapi/client.rb

Constant Summary collapse

DEFAULT_BASE_URL =
'https://api.parseapi.com'.freeze
DEFAULT_TIMEOUT =
10
DEFAULT_RETRIES =
2
RETRY_STATUS =
[429, 500, 502, 503, 504].freeze
RETRY_AFTER_CAP =
5.0
NETWORK_ERRORS =
[
	Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::ETIMEDOUT,
	Net::OpenTimeout, Net::ReadTimeout, IOError, EOFError, SocketError
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil, base_url: nil, timeout: nil, retries: nil) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
# File 'lib/parseapi/client.rb', line 30

def initialize(api_key = nil, base_url: nil, timeout: nil, retries: nil)
	@api_key = api_key || ENV['PARSEAPI_KEY']
	raise ArgumentError, 'parseapi: missing API key. Pass one or set PARSEAPI_KEY.' if @api_key.nil? || @api_key.empty?

	@base_url = URI((base_url || ENV['PARSEAPI_BASE_URL'] || DEFAULT_BASE_URL).sub(%r{/+\z}, ''))
	@timeout = timeout || DEFAULT_TIMEOUT
	@retries = retries || DEFAULT_RETRIES
	@http = nil
end

Instance Method Details

#city(name, country: nil, state: nil) ⇒ Object



78
79
80
# File 'lib/parseapi/client.rb', line 78

def city(name, country: nil, state: nil)
	get("/city/#{seg(name)}", country: country, state: state)
end

#city_id(id) ⇒ Object



82
83
84
# File 'lib/parseapi/client.rb', line 82

def city_id(id)
	get("/city/id/#{seg(id)}")
end

#city_nearest(lat, lon) ⇒ Object



90
91
92
# File 'lib/parseapi/client.rb', line 90

def city_nearest(lat, lon)
	get('/city', lat: lat, lon: lon)
end

#city_search(q, country: nil, state: nil, limit: nil) ⇒ Object



86
87
88
# File 'lib/parseapi/client.rb', line 86

def city_search(q, country: nil, state: nil, limit: nil)
	get('/city', q: q, country: country, state: state, limit: limit)
end

#continent(code) ⇒ Object



50
51
52
# File 'lib/parseapi/client.rb', line 50

def continent(code)
	get("/continent/#{seg(code)}")
end

#continent_countries(code) ⇒ Object



54
55
56
# File 'lib/parseapi/client.rb', line 54

def continent_countries(code)
	get("/continent/#{seg(code)}/countries")
end

#country(code) ⇒ Object



58
59
60
# File 'lib/parseapi/client.rb', line 58

def country(code)
	get("/country/#{seg(code)}")
end

#country_states(code) ⇒ Object



62
63
64
# File 'lib/parseapi/client.rb', line 62

def country_states(code)
	get("/country/#{seg(code)}/states")
end

#currency(code) ⇒ Object



126
127
128
# File 'lib/parseapi/client.rb', line 126

def currency(code)
	get("/currency/#{seg(code)}")
end

#currency_rate(base, quote) ⇒ Object



130
131
132
# File 'lib/parseapi/client.rb', line 130

def currency_rate(base, quote)
	get("/currency/#{seg(base)}/#{seg(quote)}")
end

#district(code, country: nil) ⇒ Object



74
75
76
# File 'lib/parseapi/client.rb', line 74

def district(code, country: nil)
	get("/district/#{seg(code)}", country: country)
end

#domain(domain, deep: false) ⇒ Object



114
115
116
# File 'lib/parseapi/client.rb', line 114

def domain(domain, deep: false)
	get("/domain/#{seg(domain)}", deep: deep)
end

#elevation(lat, lon) ⇒ Object



150
151
152
# File 'lib/parseapi/client.rb', line 150

def elevation(lat, lon)
	get('/elevation', lat: lat, lon: lon)
end

#email(email, deep: false) ⇒ Object



106
107
108
# File 'lib/parseapi/client.rb', line 106

def email(email, deep: false)
	get("/email/#{seg(email)}", deep: deep)
end

#emoji(emoji) ⇒ Object



162
163
164
# File 'lib/parseapi/client.rb', line 162

def emoji(emoji)
	get("/emoji/#{seg(emoji)}")
end

#emoji_search(q, limit: nil) ⇒ Object



166
167
168
# File 'lib/parseapi/client.rb', line 166

def emoji_search(q, limit: nil)
	get('/emoji', q: q, limit: limit)
end

#holiday(country, year: nil) ⇒ Object



142
143
144
# File 'lib/parseapi/client.rb', line 142

def holiday(country, year: nil)
	get("/holiday/#{seg(country)}", year: year)
end

#holiday_date(country, date) ⇒ Object



146
147
148
# File 'lib/parseapi/client.rb', line 146

def holiday_date(country, date)
	get("/holiday/#{seg(country)}/#{seg(date)}")
end

#ip(ip, deep: false) ⇒ Object

--- Lookup methods (one per endpoint, named after the route) ---



42
43
44
# File 'lib/parseapi/client.rb', line 42

def ip(ip, deep: false)
	get("/ip/#{seg(ip)}", deep: deep)
end

#ip_self(deep: false) ⇒ Object



46
47
48
# File 'lib/parseapi/client.rb', line 46

def ip_self(deep: false)
	get('/ip', deep: deep)
end

#language(code) ⇒ Object



134
135
136
# File 'lib/parseapi/client.rb', line 134

def language(code)
	get("/language/#{seg(code)}")
end

#mx(domain) ⇒ Object



118
119
120
# File 'lib/parseapi/client.rb', line 118

def mx(domain)
	get("/mx/#{seg(domain)}")
end

#phone(number, country: nil, deep: false) ⇒ Object



110
111
112
# File 'lib/parseapi/client.rb', line 110

def phone(number, country: nil, deep: false)
	get("/phone/#{seg(number)}", country: country, deep: deep)
end

#point(lat, lon, deep: false) ⇒ Object



154
155
156
# File 'lib/parseapi/client.rb', line 154

def point(lat, lon, deep: false)
	get('/point', lat: lat, lon: lon, deep: deep)
end

#postal(code, country:) ⇒ Object



94
95
96
# File 'lib/parseapi/client.rb', line 94

def postal(code, country:)
	get("/postal/#{seg(code)}", country: country)
end

#postal_distance(from, to, country:) ⇒ Object



102
103
104
# File 'lib/parseapi/client.rb', line 102

def postal_distance(from, to, country:)
	get("/postal/#{seg(from)}/distance/#{seg(to)}", country: country)
end

#postal_nearby(code, country:, radius: nil, unit: nil) ⇒ Object



98
99
100
# File 'lib/parseapi/client.rb', line 98

def postal_nearby(code, country:, radius: nil, unit: nil)
	get("/postal/#{seg(code)}/nearby", country: country, radius: radius, unit: unit)
end

#state(code, country:) ⇒ Object



66
67
68
# File 'lib/parseapi/client.rb', line 66

def state(code, country:)
	get("/state/#{seg(code)}", country: country)
end

#state_districts(code, country:) ⇒ Object



70
71
72
# File 'lib/parseapi/client.rb', line 70

def state_districts(code, country:)
	get("/state/#{seg(code)}/districts", country: country)
end

#timezone(id, at: nil) ⇒ Object



138
139
140
# File 'lib/parseapi/client.rb', line 138

def timezone(id, at: nil)
	get("/timezone/#{seg(id)}", at: at)
end

#useragent(ua, deep: false) ⇒ Object



122
123
124
# File 'lib/parseapi/client.rb', line 122

def useragent(ua, deep: false)
	get('/useragent', { deep: deep }, { 'User-Agent' => ua })
end

#weather(lat, lon, deep: false) ⇒ Object



158
159
160
# File 'lib/parseapi/client.rb', line 158

def weather(lat, lon, deep: false)
	get('/weather', lat: lat, lon: lon, deep: deep)
end