Class: AwsService
- Inherits:
-
Object
- Object
- AwsService
- Defined in:
- app/services/AwsService.rb
Instance Attribute Summary collapse
-
#get_path ⇒ Object
readonly
Returns the value of attribute get_path.
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Instance Method Summary collapse
- #fetch_project_json ⇒ Object
-
#initialize ⇒ AwsService
constructor
A new instance of AwsService.
- #publish_project_json(json) ⇒ Object
Constructor Details
#initialize ⇒ AwsService
Returns a new instance of AwsService.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/services/AwsService.rb', line 7 def initialize # @aws_s3_bucket_name = 'polyglot-assets' @aws_s3_bucket_name = Polyglot::Sync.configuration.aws_s3_bucket_name # @aws_cloudfront_host = 'd8wlqn7pvlrac.cloudfront.net' @aws_cloudfront_host = Polyglot::Sync.configuration.aws_cloudfront_host # @organization_secret_key = 'c4ca4238a0b923820dcc509a6f75849b' @organization_secret_key = Polyglot::Sync.configuration.organization_secret_key # @project_slug = 'polyglot' @project_slug = Polyglot::Sync.configuration.project_slug # @aws_region = 'eu-west-1' @aws_region = Polyglot::Sync.configuration.aws_region @json = fetch_project_json end |
Instance Attribute Details
#get_path ⇒ Object (readonly)
Returns the value of attribute get_path.
6 7 8 |
# File 'app/services/AwsService.rb', line 6 def get_path @get_path end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
5 6 7 |
# File 'app/services/AwsService.rb', line 5 def json @json end |
Instance Method Details
#fetch_project_json ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'app/services/AwsService.rb', line 26 def fetch_project_json # @get_path = "https://#{@aws_cloudfront_host}/#{@organization_secret_key}/#{@project_slug}/all.json" @get_path = "https://#{@aws_s3_bucket_name}.s3-#{@aws_region}.amazonaws.com/#{@organization_secret_key}/#{@project_slug}/all.json" uri = URI(@get_path) result = Net::HTTP.get(uri) json = JSON.parse(result) end |
#publish_project_json(json) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/services/AwsService.rb', line 35 def publish_project_json(json) path_to_file = "all.json" File.delete(path_to_file) if File.exist?(path_to_file) json_file = File.new(path_to_file, 'a') json_file.write(json) json_file.close s3 = Aws::S3::Resource.new(region: @aws_region) obj = s3.bucket(@aws_s3_bucket_name).object("#{@organization_secret_key}/#{@project_slug}/#{path_to_file}") obj.upload_file(path_to_file, content_type: 'application/json') File.delete(path_to_file) if File.exist?(path_to_file) end |