alula-ruby 0.50.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +14 -0
  3. data/.env.example +8 -0
  4. data/.github/workflows/gem-push.yml +45 -0
  5. data/.gitignore +23 -0
  6. data/.rspec +3 -0
  7. data/.travis.yml +7 -0
  8. data/Dockerfile +6 -0
  9. data/Gemfile +12 -0
  10. data/Guardfile +42 -0
  11. data/README.md +423 -0
  12. data/Rakefile +6 -0
  13. data/VERSION.md +84 -0
  14. data/alula-docker-compose.yml +80 -0
  15. data/alula.gemspec +38 -0
  16. data/bin/console +15 -0
  17. data/bin/docparse +36 -0
  18. data/bin/genresource +79 -0
  19. data/bin/setup +8 -0
  20. data/bin/testauth +24 -0
  21. data/bin/testprep +9 -0
  22. data/data/docs/Alula_API_Documentation_2021-04-06.html +16240 -0
  23. data/docker-compose.yml +11 -0
  24. data/lib/alula/alula_response.rb +20 -0
  25. data/lib/alula/api_operations/delete.rb +52 -0
  26. data/lib/alula/api_operations/list.rb +45 -0
  27. data/lib/alula/api_operations/request.rb +44 -0
  28. data/lib/alula/api_operations/save.rb +81 -0
  29. data/lib/alula/api_resource.rb +196 -0
  30. data/lib/alula/client.rb +142 -0
  31. data/lib/alula/errors.rb +169 -0
  32. data/lib/alula/filter_builder.rb +271 -0
  33. data/lib/alula/helpers/device_attribute_translations.rb +68 -0
  34. data/lib/alula/list_object.rb +64 -0
  35. data/lib/alula/meta.rb +16 -0
  36. data/lib/alula/monkey_patches.rb +24 -0
  37. data/lib/alula/oauth.rb +118 -0
  38. data/lib/alula/pagination.rb +25 -0
  39. data/lib/alula/procedures/dealer_device_stats_proc.rb +16 -0
  40. data/lib/alula/procedures/dealer_restore_proc.rb +25 -0
  41. data/lib/alula/procedures/dealer_suspend_proc.rb +25 -0
  42. data/lib/alula/procedures/device_assign_proc.rb +23 -0
  43. data/lib/alula/procedures/device_cellular_history_proc.rb +33 -0
  44. data/lib/alula/procedures/device_rateplan_get_proc.rb +21 -0
  45. data/lib/alula/procedures/device_register_proc.rb +31 -0
  46. data/lib/alula/procedures/device_signal_add_proc.rb +42 -0
  47. data/lib/alula/procedures/device_signal_delivered_proc.rb +31 -0
  48. data/lib/alula/procedures/device_signal_update_proc.rb +32 -0
  49. data/lib/alula/procedures/device_unassign_proc.rb +16 -0
  50. data/lib/alula/procedures/device_unregister_proc.rb +21 -0
  51. data/lib/alula/procedures/upload_touchpad_branding_proc.rb +24 -0
  52. data/lib/alula/procedures/user_plansvideo_price_get.rb +21 -0
  53. data/lib/alula/procedures/user_transfer_accept.rb +19 -0
  54. data/lib/alula/procedures/user_transfer_authorize.rb +18 -0
  55. data/lib/alula/procedures/user_transfer_cancel.rb +18 -0
  56. data/lib/alula/procedures/user_transfer_deny.rb +19 -0
  57. data/lib/alula/procedures/user_transfer_reject.rb +19 -0
  58. data/lib/alula/procedures/user_transfer_request.rb +19 -0
  59. data/lib/alula/query_interface.rb +142 -0
  60. data/lib/alula/rate_limit.rb +11 -0
  61. data/lib/alula/relationship_attributes.rb +107 -0
  62. data/lib/alula/resource_attributes.rb +206 -0
  63. data/lib/alula/resources/admin_user.rb +207 -0
  64. data/lib/alula/resources/billing_program.rb +41 -0
  65. data/lib/alula/resources/dealer.rb +218 -0
  66. data/lib/alula/resources/dealer_account_transfer.rb +172 -0
  67. data/lib/alula/resources/dealer_address.rb +89 -0
  68. data/lib/alula/resources/dealer_branding.rb +226 -0
  69. data/lib/alula/resources/dealer_program.rb +75 -0
  70. data/lib/alula/resources/dealer_suspension_log.rb +49 -0
  71. data/lib/alula/resources/device.rb +716 -0
  72. data/lib/alula/resources/device_cellular_status.rb +134 -0
  73. data/lib/alula/resources/device_charge.rb +70 -0
  74. data/lib/alula/resources/device_event_log.rb +167 -0
  75. data/lib/alula/resources/device_program.rb +54 -0
  76. data/lib/alula/resources/event_trigger.rb +75 -0
  77. data/lib/alula/resources/event_webhook.rb +47 -0
  78. data/lib/alula/resources/feature_bysubject.rb +74 -0
  79. data/lib/alula/resources/feature_plan.rb +57 -0
  80. data/lib/alula/resources/feature_planvideo.rb +54 -0
  81. data/lib/alula/resources/feature_price.rb +46 -0
  82. data/lib/alula/resources/receiver_connection.rb +95 -0
  83. data/lib/alula/resources/receiver_group.rb +74 -0
  84. data/lib/alula/resources/revision.rb +91 -0
  85. data/lib/alula/resources/self.rb +61 -0
  86. data/lib/alula/resources/station.rb +130 -0
  87. data/lib/alula/resources/token_exchange.rb +34 -0
  88. data/lib/alula/resources/user.rb +229 -0
  89. data/lib/alula/resources/user_address.rb +121 -0
  90. data/lib/alula/resources/user_phone.rb +116 -0
  91. data/lib/alula/resources/user_preferences.rb +57 -0
  92. data/lib/alula/resources/user_pushtoken.rb +75 -0
  93. data/lib/alula/resources/user_videoprofile.rb +38 -0
  94. data/lib/alula/rest_resource.rb +17 -0
  95. data/lib/alula/rpc_resource.rb +40 -0
  96. data/lib/alula/rpc_response.rb +14 -0
  97. data/lib/alula/singleton_rest_resource.rb +26 -0
  98. data/lib/alula/util.rb +107 -0
  99. data/lib/alula/version.rb +5 -0
  100. data/lib/alula.rb +135 -0
  101. data/lib/parser.rb +199 -0
  102. metadata +282 -0
data/VERSION.md ADDED
@@ -0,0 +1,84 @@
1
+ # Versioning Log
2
+
3
+ | Version | Date | Description |
4
+ | ------- | --------- | --------------------------------------------------------------------------- |
5
+ | v0.1.0 | 2019-7-25 | Initial release, GET and POST devices, dealer_addresses, user, self |
6
+ | v0.1.6 | 2019-8-7 | Added Dealers and Branding, bug with non-patchable attributes, client grant |
7
+ | v0.1.7 | 2019-8-8 | Adds RequestStore as a thread-safe storage system for tokens, auth keys, and debug info |
8
+ | v0.1.8 | 2019-8-9 | Bugfix, switches api_root in Alula::Client to api_url |
9
+ | v0.1.9 | 2019-8-16 | <ol><li>Scrubs sensitive keys from VCR cassettes. API tokens, Auth keys.</li><li>Fixes the lack of omitRelationships being used, much faster now!</li><li>Tweaks how pagination works so our API mirrors that of ActiveRecord API</li><li>Adds mobile_branding field to Dealer resource</li><li>Adds connected_panel field to Device resource</li><li>Removes patchability for is_enabled on DealerBranding resource</li>|
10
+ | v0.1.10 | 2019-8-19 | Adds DeviceEventLog resource. Fixes bugs for nil dates, in and out of resources |
11
+ | v0.1.11 | 2019-8-22 | Adds support for OAuth token exchanges. Adds exception for rate limit errors |
12
+ | v0.1.12 | 2019-8-23 | Parses expiration dates better |
13
+ | v0.2.0 | 2019-9-3 | Adds fluent query interface |
14
+ | v0.2.1 | 2019-9-13 | Adds a query method for `or_like` queries. Adds CircleCI config |
15
+ | v0.3.0 | 2019-9-24 | Adds log output from client, field omission based on u_type |
16
+ | v0.4.0 | 2019-9-30 | Adds sorting of queries |
17
+ | v0.4.1 | 2019-10-2 | Handles unknown/empty errors from the API |
18
+ | v0.4.2 | 2019-10-3 | Excludes fields not annotated on the model with the `fields` property. This fixes an issue where a password hash would be used as the basis for a new user password when system users saved a user model. |
19
+ | v0.4.3 | 2019-10-3 | Adds timezone field to Dealer resource |
20
+ | v0.5.0 | 2019-10-10 | Inverts how readers & writers are set. <ol><li>Model metadata is now the be-all end-all of defining how an attribute becomes available.</li><li>Readers & writers are set during object initialization. We no longer throw `NoMethodAvailable` errors when attempting to write to an attribute that exists, but your uTYpe doesn't allow writing to. Instead we will accept the write, but continue to exclude that attribute from being sent to the API</li><li>This change fixes an issue where if the API sent down a model that was missing an attribute, we would run into `NoMethodErrors` when rendering the model. Since I don't want to safe-access check every single API model property, having concrete models is the way to go.</li></ol>)
21
+ | v0.5.1 | 2019-10-21 | Whitelists the EULA as patchable for uType 96 |
22
+ | v0.6.0 | 2019-10-28 | Implements related model loading when fetching a single model, or loading a collection. Call `.includes(:some_model, :othermodel)` in the filter chain, and if present the related models will be available after loading. |
23
+ | v0.7.0 | 2019-11-11 | Implements the start of RPC resources, beginning with Device Registration, Unregistration, Assignment, Unassignment, and Dealer Device Stats |
24
+ | v0.8.0 | 2019-11-14 | Adds the ability to create resources. Starting with the Alula::User resource, you can do .new, assign props, then call .create to issue the create call. |
25
+ | v0.8.1 | 2019-12-03 | Fixes a bug when creating a user with insufficent scopes. Errors wouldn't be reported properly. |
26
+ | v0.9.0 | 2019-12-05 | Adds the ReceiverGroup REST model |
27
+ | v0.10.0 | 2020-03-11 | Adds Docker compose for testing against a local instance of the API. Adds a model for accessing Stations |
28
+ | v0.11.0 | 2020-03-12 | Adds support for dealer.hidden, and additional fields that have been added over time. Updates generator script to output symbols as field types |
29
+ | v0.12.0 | 2020-03-16 | Updated to use userType instead of uType |
30
+ | v0.12.1 | 2020-03-18 | Fixes bug where included relationships would only appear once per unique relationship |
31
+ | v0.13.0 | 2020-03-19 | Adds Dealer and Device relationships to User model |
32
+ | v0.13.1 | 2020-03-19 | Represent self.user_type with symbols instead of strings |
33
+ | v0.13.2 | 2020-04-07 | Add back erroneously removed user.features_selected property |
34
+ | v0.14.0 | 2020-04-08 | Adds users-phones resource |
35
+ | v0.15.0 | 2020-04-13 | Adds resources for fetching the dealer suspension log, and acting on dealer.suspend and dealer.restore |
36
+ | v0.15.1 | 2020-04-23 | Changes format of errors.full_messages to match Rails. Adds accessors for values needed to automagically render forms with simple_form. |
37
+ | v0.15.2 | 2020-04-27 | Exposes RPC error codes. |
38
+ | v0.15.3 | 2020-05-11 | Avoid sending empty values when creating new records |
39
+ | v0.15.4 | 2020-05-13 | Added get relay status name to device event log |
40
+ | v0.15.5 | 2020-05-19 | Update roles for patchable and creatable for the Station model. |
41
+ | v0.16.0 | 2020-06-18 | Adds name_first and name_last fields to the Station model which are required to create a station. |
42
+ | v0.17.0 | 2020-07-15 | Adds support for event webhooks, event triggers, device signal add, update, and delivered endpoints. |
43
+ | v0.18.0 | 2020-08-04 | Adds a type: :boolean to field attributes for automatic type casting. |
44
+ | v0.19.0 | 2020-08-13 | Adds support for Account Transfer resources. |
45
+ | v0.20.0 | 2020-09-10 | Adds support for User Token resources. |
46
+ | v0.21.0 | 2020-09-15 | Adds support for defining a default blank value on REST attributes. Allows coercing of '' into nil on assignment, etc. |
47
+ | v0.22.0 | 2020-09-15 | Updates filterability of IMEI and Caller ID Phone Number on the device model |
48
+ | v0.23.0 | 2020-09-17 | Includes cellular status/history and user preference endpoints |
49
+ | v0.23.1 | 2020-10-20 | Fixes a bug where the Deny and Reject transfer RPC endpoints were not passing their `description` param as `reason`, resulting in missing data. |
50
+ | v0.23.2 | 2020-12-11 | Adds support for converting helix CRC values to hex |
51
+ | v0.23.3 | 2020-12-15 | Adds additional program IDs to hex CRC conversion evaluator |
52
+ | v0.24.0 | 2020-12-16 | Adds the ability to set a User Agent |
53
+ | v0.25.0 | 2020-12-29 | Adds models for FeaturePlan, BillingProgram, and DealerProgram resources |
54
+ | v0.26.0 | 2021-02-24 | Adds a model for ReceiverConnection |
55
+ | v0.27.0 | 2021-03-10 | Adds a model for Revision |
56
+ | v0.28.0 | 2021-03-11 | Adds a model for DevicePrograms |
57
+ | v0.28.1 | 2021-03-11 | Safely handle relationships for which no matching data is provided |
58
+ | v0.28.2 | 2021-03-11 | Adds the ability for system users to set the date_created when creating Device Programs |
59
+ | v0.29.0 | 2021-03-11 | Adds show_prices to the dealer resource. |
60
+ | v0.30.0 | 2021-05-12 | Changes PATCH requests to only send changed attributes |
61
+ | v0.31.0 | 2021-05-13 | Updates blank value coersion (translate `''` to `nil`) to apply universally, instead of being a per-field setting |
62
+ | v0.32.0 | 2021-05-19 | Adds a RPC for getting a device rate plan and fixes several relationships |
63
+ | v0.33.0 | 2021-05-27 | Adds a RPC for getting a user video plan, the user addresses REST resource, and some methods for getting the user role/role name on a user |
64
+ | v0.34.0 | 2021-06-23 | Adds model for Device Charge |
65
+ | v0.35.0 | 2021-06-23 | Adds methods that transform program_id and auto_cfg into usable strings on the Device model |
66
+ | v0.36.0 | 2021-07-21 | Adds ICCID as a filterable field for devices. |
67
+ | v0.37.0 | 2021-09-22 | Updates DealerBranding with new resource fields. |
68
+ | v0.37.1 | 2021-09-30 | Fixes issuing POST requests for resources that share a Primary ID with a parent record (DealerBranding & Dealer for example)|
69
+ | v0.38.0 | 2021-10-01 | Models & provides Rate Limiting information on fetched resources and fetched collections |
70
+ | v0.39.0 | 2021-12-02 | Added a proc to upload the touchpad branding package |
71
+ | v0.40.0 | 2021-12-06 | Added device trouble filters to device resource |
72
+ | v0.41.0 | 2022-01-07 | Added device feature filters to device resource |
73
+ | v0.42.0 | 2022-01-12 | Updates RPC classes to throw exceptions when encountering server-side critical errors |
74
+ | v0.43.0 | 2022-01-13 | Added video profiles to user resource |
75
+ | v0.44.0 | 2022-01-14 | Adds Feature Plan & related models |
76
+ | v0.44.1 | 2022-01-21 | Fixes a bug where sometimes `.list_all` would not be available in a query chain |
77
+ | v0.44.2 | 2022-02-02 | Fixes a bug where invalid dates like `0000-00-00` would cause the library to choke on data load. Now the invalid string passes thru to the consumer |
78
+ | v0.45.0 | 2022-02-03 | Adds support for the AdminUser resource |
79
+ | v0.46.0 | 2022-02-22 | Support for creating sub station users |
80
+ | v0.47.0 | 2022-02-18 | Adds support for the hidden station resource |
81
+ | v0.48.0 | 2022-02-18 | Adds support for issuing DELETE requests, adds them to VideoPlans and FeaturePlans |
82
+ | v0.49.0 | 2022-03-07 | Adds key for Alarm Verification. Keeps old key - will need to be removed |
83
+ | v0.50.0 | 2022-03-14 | Makes list_all a lazy loader |
84
+ | v0.50.1 | 2022-03-21 | Publishes gem to Github and Rubygems |
@@ -0,0 +1,80 @@
1
+ version: '3.2'
2
+ services:
3
+ alula-swarm-test-helper:
4
+ command: ''
5
+ image: 6z1wlx5zf1.execute-api.us-east-1.amazonaws.com/alula/alula-swarm-test-helper
6
+ depends_on:
7
+ - mariadb
8
+ - mongodb
9
+ deploy:
10
+ replicas: 1
11
+ environment:
12
+ MARIADB_ADDRESS: mariadb
13
+ MONGODB_ADDRESS: mongodb
14
+ MARIADB_PASS: ''
15
+ MARIADB_USER: root
16
+ ports:
17
+ - published: 8850
18
+ target: 80
19
+ restart: always
20
+ ipdapi:
21
+ depends_on:
22
+ - mariadb
23
+ - mongodb
24
+ - rabbitmq
25
+ deploy:
26
+ replicas: 1
27
+ environment:
28
+ HFA_ADDRESS: hfa
29
+ IPDAPI_AUTO_CREATE_DATABASES: "true"
30
+ IPDAPI_AUTO_SCHEMA_MIGRATIONS: "true"
31
+ IPDAPI_DFS_CLIENT_ID: 10211607-dd43-464b-8cfb-0d8b78beee1e
32
+ IPDAPI_DFS_CLIENT_SECRET: dfspass
33
+ IPDAPI_HFA_CLIENT_ID: c35a00cb-624d-41cc-9528-aac367ecf690
34
+ IPDAPI_HFA_CLIENT_SECRET: hfapass
35
+ IPDAPI_MPA_CLIENT_ID: 0a98a1dd-1c42-4891-9bb4-d4d8f705b64e
36
+ IPDAPI_MPA_CLIENT_SECRET: mpapass
37
+ MARIADB_ADDRESS: mariadb
38
+ MARIADB_PASS: ''
39
+ MARIADB_USER: root
40
+ MONGODB_ADDRESS: mongodb
41
+ MPA_ADDRESS: mpa
42
+ RMQ_EPHEMERAL_ADDRESS: rabbitmq
43
+ RMQ_PERSISTENT_ADDRESS: rabbitmq
44
+ REDIS_ADDRESS: redis
45
+ image: 6z1wlx5zf1.execute-api.us-east-1.amazonaws.com/alula/ipdapi:latest-staging
46
+ ports:
47
+ - published: 8800
48
+ target: 80
49
+ restart: always
50
+ mariadb:
51
+ command:
52
+ - --wait_timeout=28800
53
+ - --max_connections=2048
54
+ deploy:
55
+ endpoint_mode: dnsrr
56
+ replicas: 1
57
+ environment:
58
+ MYSQL_ALLOW_EMPTY_PASSWORD: "true"
59
+ MYSQL_DATABASES: eacs_v1,aes_v1,api_oauth,ipdt_gm
60
+ image: mariadb:10.1.33
61
+ restart: always
62
+ volumes:
63
+ - target: /var/lib/mysql/
64
+ type: tmpfs
65
+ mongodb:
66
+ deploy:
67
+ replicas: 1
68
+ image: mongo:4.4.1-bionic
69
+ restart: always
70
+ rabbitmq:
71
+ deploy:
72
+ replicas: 1
73
+ image: rabbitmq:3-management-alpine
74
+ restart: always
75
+ redis:
76
+ deploy:
77
+ replicas: 1
78
+ image: redis:6.0.9-alpine
79
+ restart: always
80
+
data/alula.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "alula/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "alula-ruby"
9
+ spec.version = Alula::VERSION
10
+ spec.required_ruby_version = ">= 2.1.0"
11
+ spec.summary = "Ruby bindings for the Alula API"
12
+
13
+ spec.authors = ["Titus Johnson"]
14
+ spec.email = ["titus.johnson@alula.net"]
15
+
16
+ spec.description = "Alula Ruby API Client"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_dependency "httparty", "~> 0.18.1"
28
+ spec.add_dependency 'request_store', '~> 1.0'
29
+
30
+ spec.add_development_dependency "bundler", "~> 2.0"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "nokogiri", "~> 1.10.3"
34
+ spec.add_development_dependency "dotenv"
35
+ spec.add_development_dependency "guard-rspec"
36
+ spec.add_development_dependency "activesupport"
37
+ spec.add_development_dependency "timecop"
38
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "alula"
5
+ require "./spec/helpers/fixture"
6
+ require "dotenv/load"
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/docparse ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "./lib/parser"
4
+ require "byebug"
5
+ require "nokogiri"
6
+ require "yaml"
7
+ require "json"
8
+ require "fileutils"
9
+
10
+ require "parser"
11
+
12
+ files = Parser::Files.load
13
+
14
+ puts "Parsing docs for #{files.length} files."
15
+ puts "If you're not seeing the files you would expect ensure they are named according to the README"
16
+
17
+ files.each_pair do |category, file|
18
+ unless file
19
+ puts "No file found for #{category} category"
20
+ next
21
+ end
22
+
23
+ puts "Parsing for #{category} with #{file.inspect}"
24
+ structured = Parser::Engine.parse_doc(category, file)
25
+
26
+ structured.each do |endpoint|
27
+ resource_path = "./data/resource_fixtures/#{endpoint[:type]}"
28
+ FileUtils.mkdir_p resource_path
29
+
30
+ path = "#{resource_path}/#{endpoint[:name]}"
31
+ File.open(path + ".yml", 'w+') { |f| f.write(endpoint.to_yaml) }
32
+ File.open(path + '.json', 'w+') { |f| f.write(JSON.pretty_generate(endpoint)) }
33
+ end
34
+ end
35
+
36
+ puts "Parsing is done. Check yo diffs."
data/bin/genresource ADDED
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "./lib/parser"
4
+ require "byebug"
5
+ require "yaml"
6
+ require "json"
7
+ require 'active_support/inflector'
8
+ require "fileutils"
9
+ require "./lib/alula/util"
10
+
11
+ FileUtils.mkdir_p './data/generated'
12
+
13
+ ## This file is used to generate API resource code from imported API docs
14
+ ## The generated code is _not_ intended to be used directly, it is created
15
+ ## so that you can manually move the parts you need into the classes you want
16
+ ## to update. Feel free to modify this as needed to generate your code.
17
+
18
+ resource_files = Dir.glob("./data/resource_fixtures/rest/*.yml")
19
+
20
+ def user_types_to_roles_list(user_type_list)
21
+ role_list = user_type_list.split(', ')
22
+ .map{ |user_type| Alula::Util.camelize(user_type) }
23
+ .map(&:to_sym)
24
+ return "[#{role_list.map(&:inspect).join(', ')}]"
25
+ end
26
+
27
+ resource_files.each do |rf|
28
+ raw = YAML.load_file(rf)
29
+ parsed = OpenStruct.new(raw)
30
+
31
+ pp rf
32
+
33
+ fields = parsed.fields == false ? [] : parsed.fields.each_with_object([]) do |field, arry|
34
+ arry << "field :#{Alula::Util.underscore(field['name'])},
35
+ type: #{field['name'].match(/date/) ? ":date" : ":string" },
36
+ sortable: #{field['sortable'] == 'true'},
37
+ filterable: #{field['filterable'] == 'true'},
38
+ creatable_by: #{user_types_to_roles_list(field['creatable by'])},
39
+ patchable_by: #{user_types_to_roles_list(field['patchable by'])}
40
+ "
41
+ end
42
+
43
+ relationships = parsed.relationships == false ? ['# None'] : parsed.relationships.map do |r|
44
+ "relationship :#{r['name']}, type: :'#{r['type']}', cardinality: '#{r['cardinality']}'"
45
+ end
46
+
47
+ resource_name = Alula::Util.split_on_word(parsed.name).map(&:singularize)
48
+
49
+ template = <<EOD
50
+ ##
51
+ # #{ parsed.description }
52
+ # This is an automatically generated class, intended to be used as a reference for updating
53
+ # our actual models (/lib/alula/resources) with new code generated from the Alula API docs.
54
+ # You should not import, reference, or otherwise include this into the actual gem.
55
+ # Keep it in the data folder.
56
+ module Generated
57
+ class #{resource_name.map(&:capitalize).join('')}
58
+ extend Alula::ResourceAttributes
59
+
60
+ # You should update this to be a slash-separated, literal path to the resource
61
+ # without the prefix /api/v1 or the suffix of an ID
62
+ resource_path '#{parsed.name}'
63
+
64
+ # Relationships
65
+ #{relationships.join("\n ")}
66
+
67
+ # Resource Fields
68
+ # Not all params are used at the moment. See Alula::ResourceAttributes for details
69
+ # on how params are parsed,
70
+ #{fields.join("\n ")}
71
+ end
72
+ end
73
+ EOD
74
+
75
+ path = "./data/generated/#{resource_name.join('_')}.rb"
76
+ File.open(path, "w+") { |f| f.write(template) }
77
+ end
78
+
79
+ puts "Imported resources updated from generated docs. Check yo diffs."
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/bin/testauth ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "alula"
5
+ require 'byebug'
6
+ require 'dotenv/load'
7
+
8
+
9
+ Alula::Oauth.configure(client_id: ENV.fetch('CLIENT_ID'), client_secret: ENV.fetch('CLIENT_SECRET'), api_url: ENV.fetch('API_URL'))
10
+ auth = Alula::Oauth.authenticate(username: ENV.fetch('DEALER_ACCOUNT_UN'), password: ENV.fetch('DEALER_ACCOUNT_PW'))
11
+
12
+ if auth.is_a? Alula::Oauth::Error
13
+ puts raise auth.error_description
14
+ exit
15
+ end
16
+
17
+ access_token = auth.access_token
18
+
19
+ env_file = File.open('.env').read
20
+ File.open('.env', 'w+') do |f|
21
+ f.puts env_file.gsub(/TEST_ACCESS_TOKEN=(.*)\n/, "TEST_ACCESS_TOKEN=#{access_token}\n")
22
+ end
23
+
24
+ puts ".env updated with new access token"
data/bin/testprep ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ puts `./bin/testauth`
4
+
5
+ Dir.glob('./spec/fixtures/cassettes/*.yml') do |f|
6
+ File.delete(f) if f != '.' && f != '..'
7
+ end
8
+
9
+ puts "cassettes removed, re-test at will"