Class: Flow::Cli::Utils::FlowApiManager
- Inherits:
-
Object
- Object
- Flow::Cli::Utils::FlowApiManager
- Defined in:
- lib/flow/cli/utils/api/flow_api_manager.rb
Instance Attribute Summary collapse
-
#current_flow_id ⇒ Object
Returns the value of attribute current_flow_id.
-
#current_org_id ⇒ Object
Returns the value of attribute current_org_id.
-
#current_project_id ⇒ Object
Returns the value of attribute current_project_id.
-
#current_project_name ⇒ Object
Returns the value of attribute current_project_name.
-
#email ⇒ Object
Returns the value of attribute email.
-
#password ⇒ Object
Returns the value of attribute password.
-
#user_access_token ⇒ Object
Returns the value of attribute user_access_token.
Class Method Summary collapse
Instance Method Summary collapse
- #delete_p12(p12_id, flow_id) ⇒ Object
- #delete_provision(mobileprovisions_id, flow_id) ⇒ Object
- #fetch_flow(flow_id, project_id) ⇒ Object
- #fetch_flows(project_id) ⇒ Object
- #fetch_orgs ⇒ Object
- #fetch_project(project_id) ⇒ Object
- #fetch_projects(specify_org_id = nil) ⇒ Object
- #init_access_token ⇒ Object
-
#initialize(hash = {}) {|_self| ... } ⇒ FlowApiManager
constructor
A new instance of FlowApiManager.
- #load_p12s(flow_id) ⇒ Object
- #load_provisions(flow_id) ⇒ Object
- #send_to_api(action, url, params = {}, slice_items = nil, need_access_token = true) ⇒ Object
- #standard_file(file) ⇒ Object
-
#upload_p12(flow_id, file, password = nil) ⇒ Object
5909e8c4ef2cb07bcefc3dbd.
- #upload_provision(flow_id, file) ⇒ Object
Constructor Details
#initialize(hash = {}) {|_self| ... } ⇒ FlowApiManager
Returns a new instance of FlowApiManager.
9 10 11 12 13 14 15 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 9 def initialize(hash = {}) i[email password user_access_token].each do |item| send "#{item}=", hash[item.to_s] end yield self if block_given? init_access_token if user_access_token.nil? end |
Instance Attribute Details
#current_flow_id ⇒ Object
Returns the value of attribute current_flow_id.
5 6 7 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 5 def current_flow_id @current_flow_id end |
#current_org_id ⇒ Object
Returns the value of attribute current_org_id.
5 6 7 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 5 def current_org_id @current_org_id end |
#current_project_id ⇒ Object
Returns the value of attribute current_project_id.
5 6 7 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 5 def current_project_id @current_project_id end |
#current_project_name ⇒ Object
Returns the value of attribute current_project_name.
5 6 7 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 5 def current_project_name @current_project_name end |
#email ⇒ Object
Returns the value of attribute email.
5 6 7 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 5 def email @email end |
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 5 def password @password end |
#user_access_token ⇒ Object
Returns the value of attribute user_access_token.
5 6 7 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 5 def user_access_token @user_access_token end |
Class Method Details
.load_from_db ⇒ Object
100 101 102 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 100 def load_from_db new(DbManager.read) end |
.login(email, password) ⇒ Object
94 95 96 97 98 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 94 def login(email, password) dict = FlowApiRest.post("/login", login: email, password: password) DbManager.save(email: email, password: password) dict end |
Instance Method Details
#delete_p12(p12_id, flow_id) ⇒ Object
49 50 51 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 49 def delete_p12(p12_id, flow_id) send_to_api(:delete, "/certificates/#{p12_id}", flow_id: flow_id) end |
#delete_provision(mobileprovisions_id, flow_id) ⇒ Object
63 64 65 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 63 def delete_provision(mobileprovisions_id,flow_id) send_to_api(:delete, "/mobileprovisions/#{mobileprovisions_id}", flow_id: flow_id) end |
#fetch_flow(flow_id, project_id) ⇒ Object
67 68 69 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 67 def fetch_flow(flow_id, project_id) send_to_api(:get, "/flows/#{flow_id}", project_id: project_id) end |
#fetch_flows(project_id) ⇒ Object
33 34 35 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 33 def fetch_flows(project_id) send_to_api(:get, "/projects/#{project_id}/flows") end |
#fetch_orgs ⇒ Object
17 18 19 20 21 22 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 17 def fetch_orgs raw_orgs = FlowApiRest.get("/orgs", access_token: user_access_token) raw_orgs.map do |org| org.slice(:id, :name) end end |
#fetch_project(project_id) ⇒ Object
29 30 31 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 29 def fetch_project(project_id) send_to_api(:get, "/projects/#{project_id}") end |
#fetch_projects(specify_org_id = nil) ⇒ Object
24 25 26 27 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 24 def fetch_projects(specify_org_id = nil) org_id = specify_org_id || current_org_id send_to_api(:get, "/projects", { org_id: org_id }, i[id name git_url source]) end |
#init_access_token ⇒ Object
83 84 85 86 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 83 def init_access_token answer = self.class.login(email, password) self.user_access_token = answer[:access_token] end |
#load_p12s(flow_id) ⇒ Object
45 46 47 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 45 def load_p12s(flow_id) send_to_api(:get, "/flows/#{flow_id}/certificates") end |
#load_provisions(flow_id) ⇒ Object
59 60 61 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 59 def load_provisions(flow_id) send_to_api(:get, "/flows/#{flow_id}/mobileprovisions") end |
#send_to_api(action, url, params = {}, slice_items = nil, need_access_token = true) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 71 def send_to_api(action, url, params = {}, slice_items = nil, need_access_token = true) params[:access_token] = user_access_token if need_access_token params.compact! raw_answer = FlowApiRest.send(action, url, params) return raw_answer if slice_items.nil? raise "slice need be a array with symbols" unless slice_items.is_a? Array return raw_answer.map { |item| item.slice(*slice_items) } if raw_answer.is_a? Array raw_answer.slice(*slice_items) end |
#standard_file(file) ⇒ Object
88 89 90 91 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 88 def standard_file(file) return File.open(file) if file.is_a?(String) file end |
#upload_p12(flow_id, file, password = nil) ⇒ Object
5909e8c4ef2cb07bcefc3dbd
38 39 40 41 42 43 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 38 def upload_p12(flow_id, file, password = nil) send_to_api(:post, "/flows/#{flow_id}/certificates", file: standard_file(file), type: "ios", password: password) end |
#upload_provision(flow_id, file) ⇒ Object
53 54 55 56 57 |
# File 'lib/flow/cli/utils/api/flow_api_manager.rb', line 53 def upload_provision(flow_id, file) send_to_api(:post, "/flows/#{flow_id}/mobileprovisions", file: standard_file(file), flow_id: flow_id) end |