Class: Pod::Specification

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-alibaba-cainiao-environment/modify-aliyun-oss.rb

Class Method Summary collapse

Class Method Details

.from_file(path, subspec_name = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cocoapods-alibaba-cainiao-environment/modify-aliyun-oss.rb', line 8

def from_file(path, subspec_name = nil)
  path = Pathname.new(path)
  unless path.exist?
    raise Informative, "No podspec exists at path `#{path}`."
  end

  string = File.open(path, 'r:utf-8', &:read)
  # Work around for Rubinius incomplete encoding in 1.9 mode
  if string.respond_to?(:encoding) && string.encoding.name != 'UTF-8'
    string.encode!('UTF-8')
  end

  if path.extname == '.json' then
    pod_object = JSON.parse(string)
    if (pod_object['source'] && pod_object['source']['http'])
      pod_object['source']['http'] = process_source_http_url(pod_object['source']['http'], pod_object['version'])
      string = pod_object.to_json
    end
  end

  return from_string(string, path, subspec_name)
end

.old_from_fileObject



6
# File 'lib/cocoapods-alibaba-cainiao-environment/modify-aliyun-oss.rb', line 6

alias_method :old_from_file, :from_file

.process_source_http_url(url, version) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cocoapods-alibaba-cainiao-environment/modify-aliyun-oss.rb', line 31

def process_source_http_url(url, version)

  if url != nil then
    if url.include? 'ios-lib.oss-cn-beijing.aliyuncs.com' then
      uri = URI.parse(url)
      oss_file_object_key = uri.path
      if $endpoint.nil? || $access_key_id.nil? || $access_key_secret.nil? || $endpoint.length == 0 || $access_key_id.length == 0 || $access_key_secret.length == 0
        raise("未设置全局变量:$endpoint $access_key_id $access_key_secret")
      end

      client = Aliyun::OSS::Client.new(endpoint: $endpoint,
                                       access_key_id: $access_key_id,
                                       access_key_secret: $access_key_secret);

      bucket = client.get_bucket('ios-lib')
      # puts("url = " + url)
      # puts("oss url转换:" + oss_file_object_key[1...oss_file_object_key.length] + "-#{version}.zip")
      oss_url = bucket.object_url(oss_file_object_key[1...oss_file_object_key.length] + "-#{version}.zip", true, 3600)

      return oss_url
    end
  end

  return url
end