drone_view_api 0.1.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 07327bbcea7b1b0027da10f67071d182f2430ca84169105c217225f2abe24b6c
4
+ data.tar.gz: efa3bbf51d6a83788fdab53e9732ebb21d4a8a996376d3f135c3f1d4955ca770
5
+ SHA512:
6
+ metadata.gz: 5f6df4a17000cbc2e617f46518b6273e6c970db6a16b1c00021a42272a4575f10bf371b430fbaaf6408be24ac74e516edc30ca2173ef24e01ba98417dca7a688
7
+ data.tar.gz: ef6aaa50d50ce2f97d45275cafceae10f0f146208ee433968e2a791bb99fd15a2847e61d994464a068959021df918a8e7ed2a1e1dc91f081aaade2efd442af8b
data/.byebug_history ADDED
@@ -0,0 +1,2 @@
1
+ q
2
+ valid_for_execution
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.4
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at TODO: Write your email address. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in drone_api.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "jwt"
9
+ gem "json"
10
+ gem 'byebug'
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ drone_api (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ byebug (10.0.2)
10
+ diff-lcs (1.4.4)
11
+ json (2.6.1)
12
+ jwt (2.3.0)
13
+ rake (12.3.3)
14
+ rspec (3.10.0)
15
+ rspec-core (~> 3.10.0)
16
+ rspec-expectations (~> 3.10.0)
17
+ rspec-mocks (~> 3.10.0)
18
+ rspec-core (3.10.1)
19
+ rspec-support (~> 3.10.0)
20
+ rspec-expectations (3.10.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.10.0)
23
+ rspec-mocks (3.10.2)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.10.0)
26
+ rspec-support (3.10.2)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ byebug
33
+ drone_api!
34
+ json
35
+ jwt
36
+ rake (~> 12.0)
37
+ rspec (~> 3.0)
38
+
39
+ BUNDLED WITH
40
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # DroneApi
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/drone_api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'drone_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install drone_api
22
+
23
+ ## Usage
24
+
25
+ # Invoke Auth
26
+ DroneApi.generate_token
27
+
28
+ # Account Show
29
+ DroneApi::Accounts::Show.new.response
30
+
31
+ # Account Create
32
+ DroneApi::Accounts::Create.new(name: "Account Name", email: "test@email.com", first_name: "Account First Name", last_name: "Account Last Name").response
33
+
34
+ # Client Show
35
+ DroneApi::Clients::Show.new(1).response
36
+
37
+ # Client Create
38
+ DroneApi::Clients::Create.new(email: "test@email.com", first_name: "Client First Name", last_name: "Client Last Name", organization: "Org Name", original_client_id: 1122).response
39
+
40
+ # Building Show
41
+ DroneApi::Buildings::Show.new(1).response
42
+
43
+ # Bulding Create
44
+ DroneApi::Buildings::Create.new(name: "Building Name", address: "Address", city: "<City>", state: "<State>", zipcode: <Zip>, country: "<Country>", latitude: 123.234, longitude: 764.345, client_id: 1, original_building_id: 234).response
45
+
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+
50
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/drone_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/drone_api/blob/master/CODE_OF_CONDUCT.md).
55
+
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
60
+
61
+ ## Code of Conduct
62
+
63
+ Everyone interacting in the DroneApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/drone_api/blob/master/CODE_OF_CONDUCT.md).
64
+
65
+ # Add to initializers drone_api.rb
66
+
67
+ DroneApi.configure do |config|
68
+ config.client_id = '<username in drone>'
69
+ config.client_secret = '<password recieved from drone>'
70
+ config.account_id = '<account_id from drone>'
71
+ config.env = '<env>'
72
+ end
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "drone_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/drone_api.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/drone_api/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "drone_view_api"
5
+ spec.version = DroneApi::VERSION
6
+ spec.authors = ["saurabh gulati", "navdeep singh"]
7
+ spec.email = ["saurabhgulati159@gmail.com", "navdeepsinghsarao@gmail.com"]
8
+
9
+ spec.summary = %q{This gem enables your app to consume API's from app.droneviewpro.com. }
10
+ spec.description = %q{Provides you ability to access accounts, users, members, orthoimages, buildings and inspections.}
11
+ spec.homepage = "http://app.droneviewpro.com"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "http://github.com"
18
+ spec.add_dependency "jwt"
19
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ end
@@ -0,0 +1,47 @@
1
+ class DroneApi::Accounts::Create < DroneApi::Base
2
+
3
+ Params = Struct.new(
4
+ :name,
5
+ :email,
6
+ :first_name,
7
+ :last_name,
8
+ keyword_init: true
9
+ )
10
+
11
+ def initialize params={}
12
+ super()
13
+ @params = Params.new(params)
14
+ end
15
+
16
+ def process_response response
17
+ @response_data = JSON.parse(response)
18
+ end
19
+
20
+ private
21
+
22
+ def validate
23
+ @errors['name'] << 'Can\'t be blank' if @params.name.to_s.empty?
24
+ @errors['email'] << 'Can\'t be blank' if @params.email.to_s.empty?
25
+ @errors['first_name'] << 'Can\'t be blank' if @params.first_name.to_s.empty?
26
+ @errors['last_name'] << 'Can\'t be blank' if @params.last_name.to_s.empty?
27
+ end
28
+
29
+ def api_path
30
+ "/api/v2/accounts"
31
+ end
32
+
33
+ def request_type
34
+ 'POST'
35
+ end
36
+
37
+ def payload
38
+ {
39
+ account: {
40
+ name: @params.name,
41
+ email: @params.email,
42
+ first_name: @params.first_name,
43
+ last_name: @params.last_name
44
+ }
45
+ }
46
+ end
47
+ end
@@ -0,0 +1,16 @@
1
+ class DroneApi::Accounts::Show < DroneApi::Base
2
+
3
+ def process_response response
4
+ @response_data = JSON.parse(response)
5
+ end
6
+
7
+ private
8
+
9
+ def api_path
10
+ "/api/v2/accounts/#{@account_id}"
11
+ end
12
+
13
+ def request_type
14
+ 'GET'
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module DroneApi::Accounts
2
+ end
3
+
4
+ require 'drone_api/accounts/create'
5
+ require 'drone_api/accounts/show'
@@ -0,0 +1,46 @@
1
+ #
2
+ ## obj = DroneApi::Auth.new.response
3
+ ## obj.response_code => 401, 200, 422
4
+ ## obj.response_data => { 'token' => '<JWT token>'}
5
+ #
6
+ require 'jwt'
7
+
8
+ class DroneApi::Auth < DroneApi::Base
9
+ attr_reader :token
10
+
11
+ Params = Struct.new(
12
+ :username,
13
+ keyword_init: true
14
+ )
15
+
16
+ def initialize params={}
17
+ super()
18
+ @params = Params.new(params)
19
+ end
20
+
21
+ def execute
22
+ validate
23
+ if valid?
24
+ create_token
25
+ DroneApi.configuration.current_token = @token
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def validate
32
+ @errors['account_id'] << 'Can\'t be blank' if @account_id.to_s.empty?
33
+ @errors['username'] << 'Can\'t be blank' if @params.username.to_s.empty?
34
+ end
35
+
36
+ def payload
37
+ {
38
+ account_id: @account_id,
39
+ username: @params.username
40
+ }
41
+ end
42
+
43
+ def create_token
44
+ @token = JWT.encode payload, DroneApi.configuration&.encryption_token, 'HS512'
45
+ end
46
+ end
@@ -0,0 +1,65 @@
1
+ class DroneApi::Buildings::Create < DroneApi::Base
2
+
3
+ Params = Struct.new(
4
+ :name,
5
+ :address,
6
+ :city,
7
+ :state,
8
+ :zipcode,
9
+ :country,
10
+ :latitude,
11
+ :longitude,
12
+ :client_id,
13
+ :original_building_id,
14
+ keyword_init: true
15
+ )
16
+
17
+ def initialize params={}
18
+ super()
19
+ @params = Params.new(params)
20
+ end
21
+
22
+ def process_response response
23
+ @response_data = JSON.parse(response)
24
+ end
25
+
26
+ private
27
+
28
+ def validate
29
+ @errors['name'] << 'Can\'t be blank' if @params.name.empty?
30
+ @errors['address'] << 'Can\'t be blank' if @params.address.to_s.empty?
31
+ @errors['city'] << 'Can\'t be blank' if @params.city.to_s.empty?
32
+ @errors['state']. << 'Can\'t be blank' if @params.state.to_s.empty?
33
+ @errors['zipcode'] << 'Can\'t be blank' if @params.zipcode.to_s.empty?
34
+ @errors['country'] << 'Can\'t be blank' if @params.country.to_s.empty?
35
+ @errors['latitude'] << 'Can\'t be blank' if @params.latitude.to_s.empty?
36
+ @errors['longitude'] << 'Can\'t be blank' if @params.longitude.to_s.empty?
37
+ @errors['client_id'] << 'Can\'t be blank' if @params.client_id.to_s.empty?
38
+ @errors['original_building_id'] << 'Can\'t be blank' if @params.original_building_id.to_s.empty?
39
+ end
40
+
41
+ def api_path
42
+ "/api/v2/buildings"
43
+ end
44
+
45
+ def request_type
46
+ 'POST'
47
+ end
48
+
49
+ def payload
50
+ {
51
+ building: {
52
+ name: @params.name,
53
+ address: @params.address,
54
+ city: @params.city,
55
+ state: @params.state,
56
+ zipcode: @params.zipcode,
57
+ country: @params.country,
58
+ latitude: @params.latitude,
59
+ longitude: @params.longitude,
60
+ client_id: @params.client_id,
61
+ original_building_id: @params.original_building_id
62
+ }
63
+ }
64
+ end
65
+ end
@@ -0,0 +1,30 @@
1
+ class DroneApi::Buildings::Show < DroneApi::Base
2
+
3
+ def initialize id
4
+ super()
5
+ @id = id
6
+ end
7
+
8
+ def process_response response
9
+ @response_data = JSON.parse(response)
10
+ end
11
+
12
+ private
13
+
14
+ def api_path
15
+ "/api/v2/buildings/#{@params.id}"
16
+ end
17
+
18
+ def request_type
19
+ 'GET'
20
+ end
21
+
22
+ def payload
23
+ {
24
+ client: {
25
+ id: @params.id,
26
+ }
27
+ }
28
+ end
29
+
30
+ end
@@ -0,0 +1,5 @@
1
+ module DroneApi::Buildings
2
+ end
3
+
4
+ require 'drone_api/buildings/create'
5
+ require 'drone_api/buildings/show'
@@ -0,0 +1,50 @@
1
+ class DroneApi::Clients::Create < DroneApi::Base
2
+
3
+ Params = Struct.new(
4
+ :email,
5
+ :first_name,
6
+ :last_name,
7
+ :organization,
8
+ :original_client_id,
9
+ keyword_init: true
10
+ )
11
+
12
+ def initialize params={}
13
+ super()
14
+ @params = Params.new(params)
15
+ end
16
+
17
+ def process_response response
18
+ @response_data = JSON.parse(response)
19
+ end
20
+
21
+ private
22
+
23
+ def validate
24
+ @errors['email'] << 'Can\'t be blank' if @params.email.to_s.empty?
25
+ @errors['first_name'] << 'Can\'t be blank' if @params.first_name.to_s.empty?
26
+ @errors['last_name'] << 'Can\'t be blank' if @params.last_name.to_s.empty?
27
+ @errors['organization'] << 'Can\'t be blank' if @params.organization.to_s.empty?
28
+ @errors['original_client_id'] << 'Can\'t be blank' if @params.original_client_id.to_s.empty?
29
+ end
30
+
31
+ def api_path
32
+ "/api/v2/clients"
33
+ end
34
+
35
+ def request_type
36
+ 'POST'
37
+ end
38
+
39
+ def payload
40
+ {
41
+ client: {
42
+ email: @params.email,
43
+ first_name: @params.first_name,
44
+ last_name: @params.last_name,
45
+ organization: @params.organization,
46
+ original_client_id: @params.original_client_id
47
+ }
48
+ }
49
+ end
50
+ end
@@ -0,0 +1,29 @@
1
+ class DroneApi::Clients::Show < DroneApi::Base
2
+
3
+ def initialize id
4
+ super()
5
+ @id = id
6
+ end
7
+
8
+ def process_response response
9
+ @response_data = JSON.parse(response)
10
+ end
11
+
12
+ private
13
+
14
+ def api_path
15
+ "/api/v2/clients/#{@params.id}"
16
+ end
17
+
18
+ def request_type
19
+ 'GET'
20
+ end
21
+
22
+ def payload
23
+ {
24
+ client: {
25
+ id: @params.id,
26
+ }
27
+ }
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module DroneApi::Clients
2
+ end
3
+
4
+ require 'drone_api/clients/create'
5
+ require 'drone_api/clients/show'
@@ -0,0 +1,3 @@
1
+ module DroneApi
2
+ VERSION = "0.1.2"
3
+ end
data/lib/drone_api.rb ADDED
@@ -0,0 +1,200 @@
1
+ require "drone_api/version"
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ module DroneApi
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+
9
+ class ConfigurationError < DroneApi::Error
10
+ def message
11
+ 'Account id, client_id, client_secret must be defined in config'
12
+ end
13
+ end
14
+
15
+ class AuthError < DroneApi::Error
16
+ def message
17
+ 'Invalid auth token'
18
+ end
19
+ end
20
+
21
+ class << self
22
+ attr_accessor :configuration
23
+
24
+ def configure &blk
25
+ self.configuration ||= DroneApi::Configuration.new.tap(&blk)
26
+ end
27
+
28
+ def generate_token payload={ username: DroneApi.configuration&.client_id }
29
+ DroneApi::Auth.new(payload).response
30
+ end
31
+ end
32
+
33
+ class Configuration
34
+ attr_accessor :client_secret, :client_id, :account_id, :env, :current_token, :encryption_token
35
+
36
+ def initialize(options={})
37
+ self.client_secret = options['client_secret']
38
+ self.client_id = options['client_id']
39
+ self.account_id = options['account_id']
40
+ self.env = options['env'] || 'production'
41
+ self.encryption_token = options['encryption_token']
42
+ end
43
+ end
44
+
45
+ class Base
46
+ attr_reader :response_data, :response_status, :client_secret, :client_id, :account_id
47
+
48
+ def initialize
49
+ @client_secret = DroneApi.configuration&.client_secret
50
+ @client_id = DroneApi.configuration&.client_id
51
+ @account_id = DroneApi.configuration&.account_id
52
+ @drone_env = DroneApi.configuration&.env
53
+
54
+ raise DroneApi::ConfigurationError if !valid_for_execution
55
+
56
+ @errors = Hash.new {|h,k| h[k] = Array.new }
57
+ end
58
+
59
+ def set_auth_header(request)
60
+ if requires_authentication?
61
+ DroneApi.generate_token if DroneApi.configuration.current_token.to_s.empty?
62
+ request["Auth-Token"] = DroneApi.configuration.current_token
63
+ end
64
+ end
65
+
66
+ def is_form_request?
67
+ false
68
+ end
69
+
70
+ def response
71
+ execute
72
+ return self
73
+ end
74
+
75
+ def errors
76
+ @errors ||= {}
77
+ end
78
+
79
+ def valid?
80
+ errors.empty?
81
+ end
82
+
83
+ # def errors_hash
84
+ # { errors: errors }
85
+ # end
86
+
87
+ # def success_hash
88
+ # {}
89
+ # end
90
+
91
+ def request path, request_type, &blck
92
+ url = env_url+path
93
+ url = URI(url)
94
+ url.query = URI.encode_www_form(query_params) if query_params.any?
95
+ http = Net::HTTP.new(url.host, url.port)
96
+ # http.use_ssl = true
97
+ # http.verify_mode = OpenSSL::SSL::VERIFY_NONE
98
+ case request_type
99
+ when 'GET'
100
+ request = Net::HTTP::Get.new(url)
101
+ when 'POST'
102
+ request = Net::HTTP::Post.new(url)
103
+ when 'PUT'
104
+ request = Net::HTTP::Put.new(url)
105
+ when 'DELETE'
106
+ request = Net::HTTP::Delete.new(url)
107
+ else
108
+ raise 'Invalid request type'
109
+ end
110
+
111
+ set_auth_header(request)
112
+ if is_form_request?
113
+ request["content-type"] = 'application/x-www-form-urlencoded'
114
+ else
115
+ request["content-type"] = 'application/json'
116
+ end
117
+ yield(http, request)
118
+ end
119
+
120
+ def execute
121
+ validate
122
+ if valid?
123
+ make_request
124
+ end
125
+ end
126
+
127
+ def validate
128
+ end
129
+
130
+ def make_request
131
+ request(api_path, request_type) do |http, request|
132
+ request.body = parse_payload if payload.any?
133
+ process_request http, request
134
+ end
135
+ end
136
+
137
+ #NOTE: raise configuration error if token is invalid
138
+ ##Token is stored in DroneApi.configuration.current_token which can expire
139
+ ##So once its expire we'll rase authication error to let application handle it
140
+ ##Refresh token using DroneApi.generate_token if this error is raised
141
+
142
+ def process_request http, request
143
+ response = http.request(request)
144
+ @response_status = response.code.to_i
145
+
146
+ raise DroneApi::AuthError if @response_status == 401
147
+
148
+ process_response(response.body) if response.body
149
+ end
150
+
151
+ def request_type
152
+ raise 'Define request type in base class'
153
+ end
154
+
155
+ def api_path
156
+ raise 'Define api path of API in base class'
157
+ end
158
+
159
+ def query_params
160
+ {}
161
+ end
162
+
163
+ def parse_payload
164
+ if is_form_request?
165
+ return URI.encode_www_form(payload)
166
+ else
167
+ return payload.to_json
168
+ end
169
+ end
170
+
171
+ def env_url
172
+ if @drone_env == 'production'
173
+ return 'http://192.168.33.10:81'
174
+ elsif @drone_env == 'staging'
175
+ return 'http://drone.stg.ccubeapp.com'
176
+ else
177
+ return 'http://localhost:3001'
178
+ end
179
+ end
180
+
181
+ def requires_authentication?
182
+ true
183
+ end
184
+
185
+ private
186
+
187
+ def payload
188
+ {}
189
+ end
190
+
191
+ def valid_for_execution
192
+ !(@client_secret.to_s.empty? || @client_id.to_s.empty? || @account_id.to_s.empty?)
193
+ end
194
+ end
195
+ end
196
+
197
+ require 'drone_api/auth'
198
+ require 'drone_api/accounts'
199
+ require 'drone_api/clients'
200
+ require 'drone_api/buildings'
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: drone_view_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - saurabh gulati
8
+ - navdeep singh
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2022-03-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: jwt
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description: Provides you ability to access accounts, users, members, orthoimages,
29
+ buildings and inspections.
30
+ email:
31
+ - saurabhgulati159@gmail.com
32
+ - navdeepsinghsarao@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - ".byebug_history"
38
+ - ".gitignore"
39
+ - ".rspec"
40
+ - ".travis.yml"
41
+ - CODE_OF_CONDUCT.md
42
+ - Gemfile
43
+ - Gemfile.lock
44
+ - LICENSE.txt
45
+ - README.md
46
+ - Rakefile
47
+ - bin/console
48
+ - bin/setup
49
+ - drone_api.gemspec
50
+ - lib/drone_api.rb
51
+ - lib/drone_api/accounts.rb
52
+ - lib/drone_api/accounts/create.rb
53
+ - lib/drone_api/accounts/show.rb
54
+ - lib/drone_api/auth.rb
55
+ - lib/drone_api/buildings.rb
56
+ - lib/drone_api/buildings/create.rb
57
+ - lib/drone_api/buildings/show.rb
58
+ - lib/drone_api/clients.rb
59
+ - lib/drone_api/clients/create.rb
60
+ - lib/drone_api/clients/show.rb
61
+ - lib/drone_api/version.rb
62
+ homepage: http://app.droneviewpro.com
63
+ licenses:
64
+ - MIT
65
+ metadata:
66
+ homepage_uri: http://app.droneviewpro.com
67
+ source_code_uri: http://github.com
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 2.3.0
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.0.8
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: This gem enables your app to consume API's from app.droneviewpro.com.
87
+ test_files: []