Module: EasyqaApi

Defined in:
lib/easyqa_api/item.rb,
lib/easyqa_api/version.rb,
lib/easyqa_api/exceptions.rb,
lib/easyqa_api/items/role.rb,
lib/easyqa_api/items/user.rb,
lib/easyqa_api/items/issue.rb,
lib/easyqa_api/items/status.rb,
lib/easyqa_api/configuration.rb,
lib/easyqa_api/items/project.rb,
lib/easyqa_api/items/test_run.rb,
lib/easyqa_api/items/test_case.rb,
lib/easyqa_api/items/test_plan.rb,
lib/easyqa_api/items/test_module.rb,
lib/easyqa_api/items/test_object.rb,
lib/easyqa_api/items/organization.rb,
lib/easyqa_api/items/test_run_result.rb,
lib/easyqa_api/items/issue_attachment.rb,
lib/easyqa_api/helpers/class_methods_settable.rb

Overview

Have a class method analog

Returns:

  • (Hash)

    item attribtues on EasyQA website

See Also:

Defined Under Namespace

Modules: ClassMethodsSettable Classes: Configuration, Exception, Issue, IssueAttachment, Item, Organization, Project, Role, Status, TestCase, TestModule, TestObject, TestPlan, TestRun, TestRunResult, User

Constant Summary collapse

VERSION =

EasyqaApi gem version

'0.0.5'

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



22
23
24
# File 'lib/easyqa_api/configuration.rb', line 22

def configuration
  @configuration
end

Instance Attribute Details

#attributesHash

Returns item attributes from response body in your requests.

Returns:

  • (Hash)

    item attributes from response body in your requests



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/easyqa_api/item.rb', line 41

module EasyqaApi
  # The class for representation EasyQA objects
  class Item
    extend ClassMethodsSettable

    # constant for Faradat connection by content type
    # @see EasyqaApi::Item.json_connection
    # @see EasyqaApi::Item.multipart_connection
    CONNECTION = {
      json: {
        instance: -> { json_connection },
        content_type: 'application/json'
      },
      multipart: {
        instance: -> { multipart_connection },
        content_type: 'multipart/form-data'
      }
    }.freeze

    # Deafult user in EasyqaApi Items.
    #   If you set this attributes you can use any methods without set user in all methods
    # @see User#set_default!
    @@default_user = nil

    class << self
      # retrieve or create Faraday json connection
      # @return [Faraday::Connection] Faraday json connection
      def json_connection
        @json_connection ||= Faraday.new(url: EasyqaApi.configuration.url) do |faraday|
          faraday.request :json
          faraday.response :json
          faraday.adapter Faraday.default_adapter
        end
      end

      # retrieve or create Faraday multipart connection
      # @return [Faraday::Connection] Faraday multipart connection
      def multipart_connection
        @multipart_connection ||= Faraday.new(url: EasyqaApi.configuration.url) do |faraday|
          faraday.request :multipart
          faraday.response :json
          faraday.adapter Faraday.default_adapter
        end
      end

      # Send request to EasyQA api within default configuration
      # @param url [String] url for method
      # @param html_method [Symbol] html method for request
      # @param type [Symbol] type of request
      # @yield faraday request config
      # @example
      #   send_request('projects', :post) do |req|
      #     req.body = {
      #       project: {
      #         title: 'Test Project'
      #       },
      #       organization_id: 1,
      #       auth_token: 'IcdHzYZXDlX8SsjoOC5MV59lPVPzbaEUuUgZly3ESmopojMaN5pNlzOJCAV2_Rfe'
      #     }
      #   end
      # @return [Hash] response body
      # @raise [NotFoundError, PermissionError, RequestError, ValidationError] if request fail
      # @see EasyqaApi::Exception.check_response_status!
      # @see CONNECTION
      # @see EasyqaApi::Configuration
      def send_request(url, html_method, type = :json, &block)
        response = EasyqaApi::Item::CONNECTION[type][:instance].call.send(html_method) do |req|
          req.url EasyqaApi.configuration.api_path + url
          req.headers['Content-Type'] = EasyqaApi::Item::CONNECTION[type][:content_type]
          yield(req) if block
        end

        operation_status(response)
      end

      # Processing response
      # @param response [Faraday::Response] response of your request
      # @raise [NotFoundError, PermissionError, RequestError, ValidationError] if response not valid
      # @return [Hash] response body
      # @see EasyqaApi::Exception.check_response_status!
      def operation_status(response)
        EasyqaApi::Exception.check_response_status!(response)
        response.body
      end
    end

    def initialize(*_args)
    end

    # Install variables for Item instance if key in attribute has a valid setter in instance
    # @param arguments [Hash]
    def install_variables!(arguments)
      allowed_methods = retrive_allowed_methods
      arguments.each do |key, value|
        method_name = "#{key}=".to_sym
        send(method_name, value) if allowed_methods.include? method_name
      end
    end

    private

    def send_request(*attrs, &block)
      self.class.send_request(*attrs, &block)
    end

    def retrive_allowed_methods
      public_methods.select { |method_name| method_name =~ /[a-z]=$/ }
    end
  end
end

#idFixnum

Returns The uniq identeficator item on EasyQA website.

Returns:

  • (Fixnum)

    The uniq identeficator item on EasyQA website



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/easyqa_api/item.rb', line 41

module EasyqaApi
  # The class for representation EasyQA objects
  class Item
    extend ClassMethodsSettable

    # constant for Faradat connection by content type
    # @see EasyqaApi::Item.json_connection
    # @see EasyqaApi::Item.multipart_connection
    CONNECTION = {
      json: {
        instance: -> { json_connection },
        content_type: 'application/json'
      },
      multipart: {
        instance: -> { multipart_connection },
        content_type: 'multipart/form-data'
      }
    }.freeze

    # Deafult user in EasyqaApi Items.
    #   If you set this attributes you can use any methods without set user in all methods
    # @see User#set_default!
    @@default_user = nil

    class << self
      # retrieve or create Faraday json connection
      # @return [Faraday::Connection] Faraday json connection
      def json_connection
        @json_connection ||= Faraday.new(url: EasyqaApi.configuration.url) do |faraday|
          faraday.request :json
          faraday.response :json
          faraday.adapter Faraday.default_adapter
        end
      end

      # retrieve or create Faraday multipart connection
      # @return [Faraday::Connection] Faraday multipart connection
      def multipart_connection
        @multipart_connection ||= Faraday.new(url: EasyqaApi.configuration.url) do |faraday|
          faraday.request :multipart
          faraday.response :json
          faraday.adapter Faraday.default_adapter
        end
      end

      # Send request to EasyQA api within default configuration
      # @param url [String] url for method
      # @param html_method [Symbol] html method for request
      # @param type [Symbol] type of request
      # @yield faraday request config
      # @example
      #   send_request('projects', :post) do |req|
      #     req.body = {
      #       project: {
      #         title: 'Test Project'
      #       },
      #       organization_id: 1,
      #       auth_token: 'IcdHzYZXDlX8SsjoOC5MV59lPVPzbaEUuUgZly3ESmopojMaN5pNlzOJCAV2_Rfe'
      #     }
      #   end
      # @return [Hash] response body
      # @raise [NotFoundError, PermissionError, RequestError, ValidationError] if request fail
      # @see EasyqaApi::Exception.check_response_status!
      # @see CONNECTION
      # @see EasyqaApi::Configuration
      def send_request(url, html_method, type = :json, &block)
        response = EasyqaApi::Item::CONNECTION[type][:instance].call.send(html_method) do |req|
          req.url EasyqaApi.configuration.api_path + url
          req.headers['Content-Type'] = EasyqaApi::Item::CONNECTION[type][:content_type]
          yield(req) if block
        end

        operation_status(response)
      end

      # Processing response
      # @param response [Faraday::Response] response of your request
      # @raise [NotFoundError, PermissionError, RequestError, ValidationError] if response not valid
      # @return [Hash] response body
      # @see EasyqaApi::Exception.check_response_status!
      def operation_status(response)
        EasyqaApi::Exception.check_response_status!(response)
        response.body
      end
    end

    def initialize(*_args)
    end

    # Install variables for Item instance if key in attribute has a valid setter in instance
    # @param arguments [Hash]
    def install_variables!(arguments)
      allowed_methods = retrive_allowed_methods
      arguments.each do |key, value|
        method_name = "#{key}=".to_sym
        send(method_name, value) if allowed_methods.include? method_name
      end
    end

    private

    def send_request(*attrs, &block)
      self.class.send_request(*attrs, &block)
    end

    def retrive_allowed_methods
      public_methods.select { |method_name| method_name =~ /[a-z]=$/ }
    end
  end
end

#project_tokenString

Returns your project token.

Returns:

  • (String)

    your project token



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/easyqa_api/item.rb', line 41

module EasyqaApi
  # The class for representation EasyQA objects
  class Item
    extend ClassMethodsSettable

    # constant for Faradat connection by content type
    # @see EasyqaApi::Item.json_connection
    # @see EasyqaApi::Item.multipart_connection
    CONNECTION = {
      json: {
        instance: -> { json_connection },
        content_type: 'application/json'
      },
      multipart: {
        instance: -> { multipart_connection },
        content_type: 'multipart/form-data'
      }
    }.freeze

    # Deafult user in EasyqaApi Items.
    #   If you set this attributes you can use any methods without set user in all methods
    # @see User#set_default!
    @@default_user = nil

    class << self
      # retrieve or create Faraday json connection
      # @return [Faraday::Connection] Faraday json connection
      def json_connection
        @json_connection ||= Faraday.new(url: EasyqaApi.configuration.url) do |faraday|
          faraday.request :json
          faraday.response :json
          faraday.adapter Faraday.default_adapter
        end
      end

      # retrieve or create Faraday multipart connection
      # @return [Faraday::Connection] Faraday multipart connection
      def multipart_connection
        @multipart_connection ||= Faraday.new(url: EasyqaApi.configuration.url) do |faraday|
          faraday.request :multipart
          faraday.response :json
          faraday.adapter Faraday.default_adapter
        end
      end

      # Send request to EasyQA api within default configuration
      # @param url [String] url for method
      # @param html_method [Symbol] html method for request
      # @param type [Symbol] type of request
      # @yield faraday request config
      # @example
      #   send_request('projects', :post) do |req|
      #     req.body = {
      #       project: {
      #         title: 'Test Project'
      #       },
      #       organization_id: 1,
      #       auth_token: 'IcdHzYZXDlX8SsjoOC5MV59lPVPzbaEUuUgZly3ESmopojMaN5pNlzOJCAV2_Rfe'
      #     }
      #   end
      # @return [Hash] response body
      # @raise [NotFoundError, PermissionError, RequestError, ValidationError] if request fail
      # @see EasyqaApi::Exception.check_response_status!
      # @see CONNECTION
      # @see EasyqaApi::Configuration
      def send_request(url, html_method, type = :json, &block)
        response = EasyqaApi::Item::CONNECTION[type][:instance].call.send(html_method) do |req|
          req.url EasyqaApi.configuration.api_path + url
          req.headers['Content-Type'] = EasyqaApi::Item::CONNECTION[type][:content_type]
          yield(req) if block
        end

        operation_status(response)
      end

      # Processing response
      # @param response [Faraday::Response] response of your request
      # @raise [NotFoundError, PermissionError, RequestError, ValidationError] if response not valid
      # @return [Hash] response body
      # @see EasyqaApi::Exception.check_response_status!
      def operation_status(response)
        EasyqaApi::Exception.check_response_status!(response)
        response.body
      end
    end

    def initialize(*_args)
    end

    # Install variables for Item instance if key in attribute has a valid setter in instance
    # @param arguments [Hash]
    def install_variables!(arguments)
      allowed_methods = retrive_allowed_methods
      arguments.each do |key, value|
        method_name = "#{key}=".to_sym
        send(method_name, value) if allowed_methods.include? method_name
      end
    end

    private

    def send_request(*attrs, &block)
      self.class.send_request(*attrs, &block)
    end

    def retrive_allowed_methods
      public_methods.select { |method_name| method_name =~ /[a-z]=$/ }
    end
  end
end

Class Method Details

.setup {|@configuration| ... } ⇒ Object

Setup your params.

Examples:

You can change default params

EasyqaApi.setup do |config|
  config.url = 'http://app.geteasyqa.com/'
  config.api_version = 1
end

Yields:



33
34
35
# File 'lib/easyqa_api/configuration.rb', line 33

def self.setup
  yield @configuration
end