angie-core-api 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/angie-core-api/client.rb +62 -0
- data/lib/angie-core-api/configuration.rb +10 -0
- data/lib/angie-core-api/delivery_method.rb +17 -0
- data/lib/angie-core-api/flight.rb +8 -0
- data/lib/angie-core-api/map.rb +17 -0
- data/lib/angie-core-api/notification.rb +11 -0
- data/lib/angie-core-api/railtie.rb +9 -0
- data/lib/angie-core-api/weather.rb +9 -0
- data/lib/angie-core-api.rb +19 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c9c4e1950d918c943ea439283852bdedbc277fa08ccf9805148fd37ee7fa11ca
|
4
|
+
data.tar.gz: 33f633052bc842e7f82834af08ee0963bd5a90a1a2d43567416c75bb0a8e92f3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cf72d5f0295090bf84031a74b765ea2f788f0216099af6f9b1af5ea18b46ccd491e3957f38c6eeaa4d9a6811a96926e52f7f2d5d15d4ae4db0f19bad1e33ca8a
|
7
|
+
data.tar.gz: b10fd6db11f46e3a96e20d1a85a3f350bd8279900616f49d50fae0edba216d9673af5fe94ab5e68f678a97fc531559830b8e89ad84526a2e31b4282c471b5604
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
module AngieCoreApi
|
4
|
+
class Client
|
5
|
+
include HTTParty
|
6
|
+
|
7
|
+
read_timeout Integer(ENV["COREAPI_TIMEOUT"] || 5)
|
8
|
+
|
9
|
+
def data(http_method, url, body = {})
|
10
|
+
case http_method
|
11
|
+
when :get
|
12
|
+
parsed_response { self.class.get(api_url_for(url), headers: api_headers) }
|
13
|
+
when :post
|
14
|
+
parsed_response { self.class.post(api_url_for(url), body: body.to_json, headers: api_headers) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.data(http_method, url, body = {})
|
19
|
+
self.new.data(http_method, url, body)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def api_headers
|
25
|
+
{
|
26
|
+
"Content-Type" => "application/json",
|
27
|
+
"Authorization" => "Bearer #{AngieCoreApi.configuration.token}"
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def api_url_for(service_url)
|
32
|
+
File.join(AngieCoreApi.configuration.url, service_url)
|
33
|
+
end
|
34
|
+
|
35
|
+
def default_timeout
|
36
|
+
self.class.default_options[:timeout] || self.class.default_options[:read_timeout]
|
37
|
+
end
|
38
|
+
|
39
|
+
def parsed_response
|
40
|
+
response = yield
|
41
|
+
response.code == 200 ? response.parsed_response : nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def get(url, headers: api_headers, timeout: default_timeout)
|
45
|
+
request(:get, url, headers: headers, timeout: timeout)
|
46
|
+
end
|
47
|
+
|
48
|
+
def post(url, body: {}, headers: api_headers, timeout: default_timeout)
|
49
|
+
request(:post, url, body: body, headers: headers, timeout: timeout)
|
50
|
+
end
|
51
|
+
|
52
|
+
def patch(url, body: {}, headers: api_headers, timeout: default_timeout)
|
53
|
+
request(:patch, url, body: body, headers: headers, timeout: timeout)
|
54
|
+
end
|
55
|
+
|
56
|
+
def request(http_method, url, options = {})
|
57
|
+
response = self.class.send(http_method, url, options) rescue OpenStruct.new(code: 599, parsed_response: {})
|
58
|
+
return {} unless response.code == 200 || response.code == 201
|
59
|
+
response.parsed_response
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module AngieCoreApi
|
2
|
+
class DeliveryMethod
|
3
|
+
def initialize(mail) end
|
4
|
+
|
5
|
+
def deliver!(mail)
|
6
|
+
Notification.email(
|
7
|
+
from: mail.from,
|
8
|
+
to: mail.to,
|
9
|
+
cc: mail.cc,
|
10
|
+
bcc: mail.bcc,
|
11
|
+
subject: mail.subject,
|
12
|
+
text: mail.text_part ? mail.text_part.body&.raw_source : mail.body.raw_source,
|
13
|
+
html: mail.html_part&.body&.raw_source
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module AngieCoreApi
|
2
|
+
class Flight
|
3
|
+
def self.info(default_airport, airline, flight_number, date)
|
4
|
+
url = "/flights/#{default_airport}/#{URI.encode_www_form_component(airline)}/#{URI.encode_www_form_component(flight_number)}/#{date}"
|
5
|
+
Client.data(:get, url)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module AngieCoreApi
|
2
|
+
class Map
|
3
|
+
def self.travel_time(origin, location, radius, unit, size, zoom, locale)
|
4
|
+
url = "/maps/distancematrix/#{origin}/#{URI.encode(location)}/#{radius}/#{unit}/#{size}/#{zoom}/#{locale}"
|
5
|
+
Client.data(:get, url)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.local_places(origin, query, radius, unit, locale)
|
9
|
+
url = "/maps/places/#{origin}/#{URI.encode(query)}/#{radius}/#{unit}/#{locale}"
|
10
|
+
Client.data(:get, url)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.place_details(place_id)
|
14
|
+
Client.data(:get, "/maps/places/#{place_id}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module AngieCoreApi
|
2
|
+
autoload :Configuration, "angie-core-api/configuration"
|
3
|
+
autoload :Client, "angie-core-api/client"
|
4
|
+
autoload :Flight, "angie-core-api/flight"
|
5
|
+
autoload :Map, "angie-core-api/map"
|
6
|
+
autoload :Notification, "angie-core-api/notification"
|
7
|
+
autoload :Weather, "angie-core-api/weather"
|
8
|
+
autoload :DeliveryMethod, "angie-core-api/delivery_method"
|
9
|
+
|
10
|
+
def self.configuration
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure
|
15
|
+
yield configuration
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require "angie-core-api/railtie" if defined?(Rails::Railtie)
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: angie-core-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hussein Choroomi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.18.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.18.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '6.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: actionmailer
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '6.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '6.0'
|
55
|
+
description: Angie CoreAPI Ruby gem
|
56
|
+
email:
|
57
|
+
- info@angie.ai
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/angie-core-api.rb
|
63
|
+
- lib/angie-core-api/client.rb
|
64
|
+
- lib/angie-core-api/configuration.rb
|
65
|
+
- lib/angie-core-api/delivery_method.rb
|
66
|
+
- lib/angie-core-api/flight.rb
|
67
|
+
- lib/angie-core-api/map.rb
|
68
|
+
- lib/angie-core-api/notification.rb
|
69
|
+
- lib/angie-core-api/railtie.rb
|
70
|
+
- lib/angie-core-api/weather.rb
|
71
|
+
homepage: https://angie.ai
|
72
|
+
licenses: []
|
73
|
+
metadata:
|
74
|
+
homepage_uri: https://angie.ai
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 2.3.0
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubygems_version: 3.0.3
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Angie CoreAPI Ruby gem
|
94
|
+
test_files: []
|