Class: GaroonCat::Action
- Inherits:
-
Object
- Object
- GaroonCat::Action
- Defined in:
- lib/garoon-cat/action.rb
Direct Known Subclasses
GaroonCat::Actions::CBPAPI::BASE::GetOrganizationVersions, GaroonCat::Actions::UTIL_API::UTIL::Login
Class Method Summary collapse
Instance Method Summary collapse
-
#default_params ⇒ Hash
The default parameters of this service and its actions.
-
#execute(*args) ⇒ Object
Return values of this action.
-
#initialize(service:, key:) ⇒ Action
constructor
A new instance of Action.
Constructor Details
#initialize(service:, key:) ⇒ Action
Returns a new instance of Action.
48 49 50 51 |
# File 'lib/garoon-cat/action.rb', line 48 def initialize(service:, key:) @service = service @key = key end |
Class Method Details
.create(service:, key:) ⇒ GaroonCat::Action
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/garoon-cat/action.rb', line 10 def self.create(service:, key:) segments = { prefix:service.uri.path.split('/')[-3], service:service.uri.path.split('/')[-2], action:key.to_s, } require(class_path(segments)) class_name(segments).constantize.new(service:service, key:key) rescue LoadError => e $stderr.puts e if $DEBUG $stderr.puts 'default fallback file -- garoon-cat/action' if $DEBUG self.new(service:service, key:key) end |
Instance Method Details
#default_params ⇒ Hash
Returns the default parameters of this service and its actions.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/garoon-cat/action.rb', line 68 def default_params { header: { action: @service.name.sub(/Service$/, @key.to_s.camelize), security: { username_token: { username: @service.client.username, password: @service.client.password } }, timestamp: { created: Time.now, expires: Time.now, }, locale: 'jp' }, body: { parameters: nil } } end |
#execute(*args) ⇒ Object
Return values of this action
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/garoon-cat/action.rb', line 55 def execute(*args) request = GaroonCat::Request.new(default_params.merge({ body:{ parameters: args[0][0] } })) request_body = request.to_s response_body = @service.client.post(@service.uri, request_body) response = GaroonCat::Response.new(response_body) return response.to_params end |