Class: Pindo::ApplovinClient

Inherits:
Object
  • Object
show all
Defined in:
lib/pindo/client/applovinclient.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplovinClient

Returns a new instance of ApplovinClient.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pindo/client/applovinclient.rb', line 37

def initialize()

  # begin

    config_file = File.join(File::expand_path(Pindoconfig.instance.pindo_common_configdir), "applovin_client_config.json")
    config_json = JSON.parse(File.read(config_file))

    @applovin_management_key = config_json["applovin_management_key"]
    @applovin_base_url = config_json["applovin_base_url"]
    @requests_config = config_json["applovin_req_config"]


  # rescue => error
  # 		puts error
  #     raise Informative,  "加载applovi配置文件失败, 需要执行 pindo setup 或者pindo env dreamstudio"
  # end 
end

Instance Attribute Details

#applovin_base_urlObject

Returns the value of attribute applovin_base_url.



9
10
11
# File 'lib/pindo/client/applovinclient.rb', line 9

def applovin_base_url
  @applovin_base_url
end

#applovin_management_keyObject

Returns the value of attribute applovin_management_key.



8
9
10
# File 'lib/pindo/client/applovinclient.rb', line 8

def applovin_management_key
  @applovin_management_key
end

#request_configObject

Returns the value of attribute request_config.



10
11
12
# File 'lib/pindo/client/applovinclient.rb', line 10

def request_config
  @request_config
end

Class Method Details

.ad_unit_template_sizeObject



28
29
30
31
32
33
34
35
# File 'lib/pindo/client/applovinclient.rb', line 28

def self.ad_unit_template_size()
  	ad_format_array = [
                "small_template_1",
                "medium_template_1",
                "custom_template_1"
            ]
    return ad_format_array
end

.ad_unit_typeObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pindo/client/applovinclient.rb', line 16

def self.ad_unit_type()
  	ad_format_array = [
                "INTER",
                "BANNER",
                "REWARD",
                "MREC",
                "NATIVE",
                "APPOPEN"
            ]
    return ad_format_array
end

Instance Method Details

#create_ad_unit(ad_unit_name: nil, platform: nil, package_name: nil, ad_format: nil, template_size: nil) ⇒ Object



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
151
152
153
154
# File 'lib/pindo/client/applovinclient.rb', line 124

def create_ad_unit(ad_unit_name:nil, platform:nil, package_name:nil, ad_format:nil, template_size:nil)

	req_path = @requests_config["create_ad_unit"]["path"]
	req_url = @applovin_base_url + req_path

	body_params = {
	  name:ad_unit_name,
	  platform:platform,
	  package_name:package_name,
	  ad_format:ad_format,
	  template_size:template_size
	}

          con = Faraday.new 
          res = con.post do |req|
              req.url req_url
              req.headers['Content-Type'] = 'application/json'
              req.headers['Api-Key'] = @applovin_management_key
              req.body = body_params.to_json
          end
        result_data = nil
        puts res.body
        puts res.status
        if !res.body.nil?
            result_data = JSON.parse(res.body)    
        end
        # puts JSON.pretty_generate(result_data)
        
        return nil
	
end

#get_ad_unit_info(ad_unit_id: nil) ⇒ Object



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
# File 'lib/pindo/client/applovinclient.rb', line 55

def get_ad_unit_info(ad_unit_id:nil)
	req_path = @requests_config["get_ad_unit_info"]["path"]
	req_url = @applovin_base_url + req_path
        

	req_url = req_url + "/" + ad_unit_id.to_s


	params = {
		fields:"ad_network_settings,disabled_ad_network_settings,frequency_capping_settings,bid_floors,banner_refresh_settings,segments"
	}

	puts "req_url: #{req_url}"

          con = Faraday.new 
          res = con.get do |req|
              req.url req_url
              req.headers['Content-Type'] = 'application/json'
              req.headers['Api-Key'] = @applovin_management_key
              req.params = params
          end

         result_data = nil
         puts res.body
         puts res.status
         if !res.body.nil?
             result_data = JSON.parse(res.body)    
         end
         puts JSON.pretty_generate(result_data)

end

#get_all_ad_unit_info(limit: 50, offset: 0) ⇒ Object



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
# File 'lib/pindo/client/applovinclient.rb', line 88

def get_all_ad_unit_info(limit:50, offset:0)
	req_path = @requests_config["get_all_ad_unit_info"]["path"]
	req_url = @applovin_base_url + req_path
        
        

	puts "req_url: #{req_url}"

	params = {
		limit:limit,
		offset:offset
	}

          con = Faraday.new 
          res = con.get do |req|
              req.url req_url
              req.headers['Content-Type'] = 'application/json'
              req.headers['Api-Key'] = @applovin_management_key
              req.params = params 
          end

         result_data = nil
         puts res.body
         puts res.status
         if !res.body.nil?
             result_data = JSON.parse(res.body)   

         end
         # puts JSON.pretty_generate(result_data)

         # return result_data

         return nil
end